-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharCompare.java
More file actions
73 lines (57 loc) · 2.2 KB
/
Copy pathCharCompare.java
File metadata and controls
73 lines (57 loc) · 2.2 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Arrays;
import java.util.Scanner;
public class CharCompare {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = "";
int r = sc.nextInt();
int c = sc.nextInt();
sc.nextLine();
while(r != 0 && c != 0)
{
String names [] = new String[c];
for(int i = 0; i < c; i++)
{
names[i] = "";
}
for(int j = 0; j < r; j++)
{
line = sc.nextLine();
for(int i = 0; i < c; i++)
{
names[i] += Character.toString(line.charAt(i));
}
}
//System.out.println(Arrays.toString(names));
boolean edited = false;
do{
edited = false;
for(int i = 0; i < c-1; i ++)
{
if(names[i].toLowerCase().compareTo(names[i+1].toLowerCase()) > 0)
{
String temp = names[i];
names[i] = names[i+1];
names[i+1] = temp;
edited = true;
}
}
}while(edited);
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
System.out.print(names[j].charAt(i));
}
System.out.println();
}
r = sc.nextInt();
c = sc.nextInt();
if(r != 0 && c != 0)
{
sc.nextLine();
System.out.println();
}
}
}
}