- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
System.out.println("\nNames in alphabetical order: ");
if(name1.compareTo(name2) > 0) {
if(name2.compareTo(name3) > 0) {
System.out.printf("%s\n%s\n%s\n",
name3,
name2,
name1); //cba 2
}
else if(name3.compareTo(name2) > 0) {
System.out.printf("%s\n%s\n%s\n",
name2,
name3,
name1); //bca 3
}
}
else if(name2.compareTo(name1) > 0) {
if(name1.compareTo(name3) > 0) {
System.out.printf("%s\n%s\n%s\n",
name3,
name1,
name2); //cab 1
}
else if(name3.compareTo(name1) > 0) {
System.out.printf("%s\n%s\n%s\n",
name1,
name3,
name2); //acb 5
}
}//bac i abc
else if(name3.compareTo(name1) > 0) {
if(name1.compareTo(name2) > 0) {
System.out.printf("%s\n%s\n%s\n",
name2,
name1,
name3);
}
else if(name2.compareTo(name1) > 0) {
System.out.printf("%s\n%s\n%s\n",
name1,
name2,
name3);
}
}