-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbleshort.java
More file actions
35 lines (27 loc) · 940 Bytes
/
Copy pathbubbleshort.java
File metadata and controls
35 lines (27 loc) · 940 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
29
30
31
32
33
34
35
import java.util.*;
public class bubbleshort{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("enter size of array::");
int size = sc.nextInt();
int Array[]=new int[size];
System.out.println("enter array elements::");
for(int i=0; i<size; i++){
Array[i]=sc.nextInt();
}
for(int a=0; a<Array.length ; a++){
for(int j=0; j<Array.length-a-1; j++){
if(Array[j]>Array[j+1]){
//swap array
int temp = Array[j];
Array[j]=Array[j+1];
Array[j+1]= temp;
}
}
}
System.out.println("your shorted aarray::");
for(int a=0; a<Array.length ; a++){
System.out.print(Array[a]+" ");
}
}
}