-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain01.java
More file actions
51 lines (46 loc) · 1.33 KB
/
Copy pathMain01.java
File metadata and controls
51 lines (46 loc) · 1.33 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
public class Main01{
public static void main(String[] args) {
Main01.java_flow_control();
}
private static void java_flow_control() {
System.out.println("\n#java_flow_control");
System.out.println("##if-else if-else");
double x = 233.1;
if (Math.abs(x - 233) <= 1e-3) {
System.out.println("abs(x-233) <= 1e-3");
} else if (x > 233 + 1e-3) {
System.out.println("x > 233+1e-3");
} else {
System.out.println("x < 233-1e-3");
}
System.out.println("##switch-case-default");
int x1 = 1;
switch (x1) {
case 0:
System.out.println("x1==0");
case 1:
case 2:
System.out.println("x1==1");
default:
System.out.println("default");
}
System.out.println("##while");
int x2 = 3;
while (x2 < 5) {
System.out.printf("x2 = %d\n", x2);
x2++;
}
do {
System.out.printf("x2 = %d\n", x2);
x2--;
} while (x2 > 2);
System.out.println("##for");
int[] x3 = { 1, 4, 9 };
for (int i = 0; i < x3.length; i++) {
System.out.printf("i = %d\n", i);
}
for (int x4 : x3) {
System.out.printf("x = %d\n", x4);
}
}
}