-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathChpt03Number04.java
More file actions
46 lines (35 loc) · 1 KB
/
Copy pathChpt03Number04.java
File metadata and controls
46 lines (35 loc) · 1 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
// Sorted Names, pg 175 #4
// Write a program that asks for 3 names and displays them in ascending order.
import java.util.Scanner; // Needed for the Scanner class
public class Chpt3Number7 {
public static void main(String [] args) {
String name1, name2, name3, temp;
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
System.out.print("What is the first name? ");
name1 = keyboard.nextLine();
System.out.print("What is the second name? ");
name2 = keyboard.nextLine();
System.out.print("What is the third name? ");
name3 = keyboard.nextLine();
if (name1.charAt(0) > name2.charAt(0)) {
temp = name1;
name1 = name2;
name2 = temp;
}
if (name1.charAt(0) > name3.charAt(0)) {
temp = name1;
name1 = name3;
name3 = temp;
}
if (name2.charAt(0) > name3.charAt(0)) {
temp = name2;
name2 = name3;
name3 = temp;
}
System.out.println();
System.out.println(name1);
System.out.println(name2);
System.out.println(name3);
}
}