-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem37.java
49 lines (40 loc) · 1.01 KB
/
Problem37.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
package dimikOJ;
import java.util.Arrays;
import java.util.Scanner;
public class Problem37 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int T = input.nextInt();
while (T < 1 || T > 20) {
T = input.nextInt();
}
input.nextLine();
String[] strings = new String[T];
for (int i = 0; i < T; i++) {
String temp = input.nextLine();
strings[i] = temp;
}
input.close();
Arrays.sort(strings);
for (int i = 0; i < T; i++) {
System.out.println(strings[i]);
}
}
// we can also use this method
public static void sort(String[] myArray) {
int size = myArray.length;
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < myArray.length; j++) {
if (myArray[i].compareTo(myArray[j]) > 0) {
String temp = myArray[i];
myArray[i] = myArray[j];
myArray[j] = temp;
}
}
}
for (String string : myArray) {
System.out.println(string);
}
}
}