-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathJava-Number-Sorter.java
More file actions
41 lines (29 loc) · 1 KB
/
Copy pathJava-Number-Sorter.java
File metadata and controls
41 lines (29 loc) · 1 KB
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
import java.util.Scanner;
public class JavaNumberSorter {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count, temp;
System.out.print("Enter number of elements you want in the array : ");
count = input.nextInt();
int[] number = new int[count];
System.out.print("Enter array elements : ");
for (int i = 0; i < count; i++) {
number[i] = input.nextInt();
}
input.close();
for (int i = 0; i < count; i++) {
for (int j = i + 1; j < count; j++) {
if (number[i] > number[j]) {
temp = number[i];
number[i] = number[j];
number[j] = temp;
}
}
}
System.out.print("Array Elements in Ascending Order : ");
for (int i = 0; i < count - 1; i++) {
System.out.print(number[i] + ", ");
}
System.out.print(number[count - 1]);
}
}