forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExercise04_24.java
42 lines (26 loc) · 880 Bytes
/
Exercise04_24.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
package Ch_04;
import java.util.Scanner;
public class Exercise04_24 {
public static void main(String[] args) {
String tempCity = "";
Scanner input = new Scanner(System.in);
System.out.print("Enter the name of city 1: ");
String cityOne = input.next();
System.out.print("Enter the name of city 2: ");
String cityTwo = input.next();
System.out.print("Enter the name of city 3: ");
String cityThree = input.next();
if(cityOne.charAt(0) > cityTwo.charAt(0)) {
tempCity = cityTwo;
cityTwo = cityOne;
cityOne = tempCity;
if(cityTwo.charAt(0) > cityThree.charAt(0)) {
tempCity = cityThree;
cityThree = cityTwo;
cityTwo = tempCity;
}
}
System.out.println("The cities in alphabetical order are: "
+ cityOne + " " + cityTwo + " " + cityThree + "." );
}
}