-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment7.java
More file actions
40 lines (32 loc) · 837 Bytes
/
Assignment7.java
File metadata and controls
40 lines (32 loc) · 837 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
import java.util.*;
public class Assignment7{
public static void main(String[] args){
//Variable Declaration
Scanner sc = new Scanner(System.in);
int arr[] = new int[5], temp = 0, index_i, index_j;
//Getting User Data Input
for(int i=0; i<arr.length; i++){
System.out.print("Enter any number =");
arr[i] = sc.nextInt();
}
//Sorting the array value using Bubble Sort Algorithm
for(int i=0; i<arr.length; i++){
index_i = 0;
index_j=1;
for(int j=1; j<(arr.length-i); j++){
if(arr[index_i]>arr[index_j]){
temp=arr[index_i];
arr[index_i]=arr[index_j];
arr[index_j]=temp;
}
index_i++;
index_j++;
}
}
//Printing sorted values
System.out.println("Values are sorted using bubble as below......");
for(int data : arr){
System.out.println(data);
}
}
}