-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubblesort.java
36 lines (34 loc) · 943 Bytes
/
bubblesort.java
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
import java.util.Scanner;
public class bubblesort {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("*************** Hello 18BCI0174 - Aryan ****************");
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of elements you want to store: ");
n=sc.nextInt();
int[] a = new int[10];
System.out.println("Enter the elements of the array: ");
for(int i=0; i<n; i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
if(a[i]<a[j])
{
int temp = a[i];
a[i]=a[j];
a[j] = temp;
}
}
}
System.out.println("Sorted List ...");
for(int i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
}