-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_sort.java
More file actions
39 lines (28 loc) · 741 Bytes
/
Copy pathBubble_sort.java
File metadata and controls
39 lines (28 loc) · 741 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
public class Bubble_sort {
public static void main(String[] args) {
int nums[] = {6,5,2,9,4};
int size = nums.length;
int temp = 0;
System.out.println("original Array:");
for(int num:nums){
System.out.print(num);
}
for( int i=0; i<size;i++)
{
for(int j=0;j<size-1;j++)
{
if( nums[j] > nums[j+1])
{
temp = nums[j];
nums[j] = nums[j+1];
nums[j+1] = temp;
}
}
}
System.out.print("Sorted Array: ");
for(int num:nums)
{
System.out.print( "" + num);
}
}
}