-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.java
More file actions
76 lines (65 loc) · 2.13 KB
/
Copy pathMenu.java
File metadata and controls
76 lines (65 loc) · 2.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
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
74
75
76
// do-while to process a menu selection
public class Menu {
public static void main(String args[]) throws java.io.IOException{
char choice;
do{
System.out.println("Help on: ");
System.out.println(" 1. if");
System.out.println(" 2. switch");
System.out.println(" 3. while");
System.out.println(" 4. do-while");
System.out.println(" 5. for\n");
System.out.println("Choose one:");
choice = (char) System.in.read();
}while(choice < '1' || choice > '5');
System.out.println("\n");
switch(choice){
case '1':
System.out.println("The if:\n");
System.out.println("if(condition) statement;");
System.out.println("else statement");
break;
case '2':
System.out.println("The switch:\n");
System.out.println("switch(expression) {");
System.out.println(" case constant:");
System.out.println(" statement sequence");
System.out.println(" break;");
System.out.println(" //...");
System.out.println("}");
break;
case '3':
System.out.println("The while:\n");
System.out.println("while(condition) statement;");
break;
case '4':
System.out.println("The do-while:\n");
System.out.println("do {");
System.out.println(" statement;");
System.out.println("} while(condition);");
break;
case '5':
System.out.println("The for:\n");
System.out.println("for(init; condition; iteration)");
System.out.println(" statement;");
break;
}
}
}
/*
Help on:
1. if
2. switch
3. while
4. do-while
5. for
Choose one:
2
The switch:
switch(expression) {
case constant:
statement sequence
break;
//...
}
*/