-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble.java
More file actions
37 lines (28 loc) · 1.01 KB
/
Copy pathbubble.java
File metadata and controls
37 lines (28 loc) · 1.01 KB
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
36
37
import java.util.*;
public class bubble {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("enter size of array");
int size = sc.nextInt();
int arry[]=new int[size];
System.out.println("enter array elements ::");
for(int i=0; i< arry.length ; i++){
arry[i] = sc.nextInt();
}
// condition for shorting arry in decending order
for(int i=0 ; i<arry.length ; i++){
for(int j=0; j<arry.length-i-1; j++){
if(arry[j]<arry[j+1]){ //// just we have change < to > thats it.
//swap array
int temp = arry[j];
arry[j]=arry[j+1];
arry[j+1]=temp;
}
}
}
System.out.println("your shorted aray::");
for(int i=0; i<arry.length; i++){
System.out.print(arry[i]+" ");
}
}
}