-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortOf.java
More file actions
53 lines (42 loc) · 1.47 KB
/
SortOf.java
File metadata and controls
53 lines (42 loc) · 1.47 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
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Arrays;
import java.util.Scanner;
public class SortOf {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = "";
int r = sc.nextInt();
int c = sc.nextInt();
while(r != 0 && c != 0)
{
String names [] = new String[n];
for(int i = 0; i < n; i++)
{
names[i]= sc.nextLine();
}
boolean edited = false;
do{
edited = false;
for(int i = 0; i < n-1; i ++)
{
if(names[i].substring(0,2).compareTo(names[i+1].substring(0,2)) > 0)
{
String temp = names[i];
names[i] = names[i+1];
names[i+1] = temp;
edited = true;
}
}
}while(edited);
for(int i = 0; i < n; i++)
{
System.out.println(names[i]);
}
r = sc.nextInt();
c = sc.nextInt();
if(r != 0 && c != 0)
{
System.out.println();
}
}
}
}