-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubbleSortDemo.java
60 lines (36 loc) · 1.08 KB
/
BubbleSortDemo.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.kn.ArrayTasks;
import java.util.Scanner;
public class BubbleSortDemo {
public static void main(String[] args) {
//Array Declaration
Scanner scan = new Scanner(System.in);
System.out.println("Enter the size of an array=");
int arr[]=new int[scan.nextInt()];
//array initialization
for(int i=0;i<arr.length;i++) {
System.out.println("enter the array elements "+(i+1));
arr[i]=scan.nextInt();
}
//array Traversing before the bubble sort
System.out.println("The Array elements before sorting =");
System.out.print("[");
for(int i=0;i<arr.length;i++)
{
System.out.print(arr[i]+" ");
}
System.out.print("]");
System.out.println(" ");
//object creation for calling the method
BubbleSort Bubble=new BubbleSort();
Bubble.bubbleSort(arr);
//array Traversing after the bubble sort
System.out.println("The Array elements after sorting =");
System.out.print("[");
for(int i :arr)
{
System.out.print(i+" ");
}
System.out.print("]");
scan.close();
}
}