-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpSwitch.java
More file actions
36 lines (34 loc) · 1.13 KB
/
Copy pathHelpSwitch.java
File metadata and controls
36 lines (34 loc) · 1.13 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
public class HelpSwitch {
public static void main(String[] args) throws java.io.IOException {
char choice, ignore;
System.out.println("Make a choice:");
System.out.println("\t1. If\n\t2. Switch\n\t3. For\n\t4. Do\n\t5. Do-while");
do {
choice = (char) System.in.read();
if (choice == 'q') {
System.out.println("Quitting!");
break;
}
do {
ignore = (char) System.in.read();
} while (ignore != '\n');
} while (choice < '1' || choice > '5');
switch (choice) {
case '1':
System.out.println("You've chosen if.");
break;
case '2':
System.out.println("You've chosen switch.");
break;
case '3':
System.out.println("You've chosen for.");
break;
case '4':
System.out.println("You've chosen do.");
break;
case '5':
System.out.println("You've chosen do-while.");
break;
}
}
}