-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sort_the_Numbers.java
34 lines (31 loc) · 973 Bytes
/
Sort_the_Numbers.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
package com.company;
import java.io.IOException;
import java.util.Scanner;
public class Sort_the_Numbers {
public static void main(String[] args) throws IOException {
//write your code here
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t != 0) {
int n = s.nextInt(), temp;
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
t--;
}
}
}