-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble.java
More file actions
52 lines (40 loc) · 997 Bytes
/
Bubble.java
File metadata and controls
52 lines (40 loc) · 997 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Bubble {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter Number of Elements: ");
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println(" ");
System.out.println("Elements");
System.out.println(" ");
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" \t ");
}
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a.length;j++)
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println(" \n");
System.out.println(" ");
System.out.println("Sorting Elements");
System.out.println(" ");
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" \t");
}
}
}