-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbubbleSort.java
More file actions
28 lines (26 loc) · 818 Bytes
/
bubbleSort.java
File metadata and controls
28 lines (26 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
public class bubbleSort{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of numbers in the array");
int n = sc.nextInt();
int[] array = new int[n];
System.out.println("Enter the array");
for(int i=0;i<n;i++){
array[i] = sc.nextInt();
}
for(int i=0;i<n;i++){
for(int j=0;j<n-i-1;j++){
if(array[j]>array[j+1]){
int temp = array[j+1];
array[j+1] = array[j];
array[j] = temp;
}
}
}
System.out.print("The sorted array is: ");
for(int i=0;i<n;i++){
System.out.print(array[i]+" ");
}
}
}