- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
Latest commit
33 lines (32 loc) · 904 Bytes
/
Copy pathBubbleSort.java
File metadata and controls
33 lines (32 loc) · 904 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
importjava.util.*;
//8013446613
classBubbleSort
{
publicstaticvoidmain(Stringargs[])
{
Scannerin = newScanner(System.in);
System.out.println("Enter the number of elements of the array");
inti = 0, t;
intl = in.nextInt();
inta[] = newint[l];
System.out.println("Enter the Elemnts in the Array");
for (i = 0; i < l; i++) {
a[i] = in.nextInt();
}
for (i = 0; i < l; i++)
{
for (intj = 0; j < (l - (1 + i)); j++)
{
if (a[j] > a[j + 1])
{
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
System.out.println("Elements in arranged ascending order are :");
for (i = 0; i < l; i++)
System.out.println(a[i]);
}
}