-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfCode.java
More file actions
89 lines (65 loc) · 2.27 KB
/
Copy pathIfCode.java
File metadata and controls
89 lines (65 loc) · 2.27 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
77
78
79
80
81
82
83
84
85
86
87
88
89
public class HelloWorld
{
public static void main(String []args)
{
int x = 0, y = 0, z = 0, k = 0;
if ( x == y ) z = 9; // x and y are equal so the boolean result is true and the statement is executed.
System.out.println("z=" + z);
z = 0;
if ( x == y )
z = 9; // This is the same as above, the single statement can be on the next line.
System.out.println("z=" + z);
z = 0;
if ( x == y ) // The two statements in the block are executed.
{
z = 9;
z = x + 3;
}
System.out.println("z=" + z);
if ( x < -1) y = 2; // x is not greater than -1 (it is zero) so the statement is not executed.
System.out.println("y=" + y);
x = y = z = 0;
if ( x == y )
z = 7; // This statement is executed.
else
z = 0;
System.out.println("z=" + z);
if ( x != y )
z = 7;
else
z = 0; // This statement is executed.
System.out.println("z=" + z);
if ( x == 0 )
{
z = 99; // This statement block is executed
k = 33;
}
else
{
z++;
k += 2;
}
System.out.println("z=" + z + " k=" + k);
x = y = z = 0;
if ( x == 2 )
z = 5;
else if ( y == 0 )
z = 2; // This statement is executed.
System.out.println("z=" + z);
z = 0;
if ( x == 2 )
z = 5;
else if ( y == 1 )
z = 2; // Neither statement is executed, both boolean results are false.
System.out.println("z=" + z);
// You can also do:
z = 0;
if ( x == 9 )
z = 5;
else if ( y == 9 )
z += 2;
else // Neither of the above comparisons are true so this else is excuted.
z = 9;
System.out.println("z=" + z);
}
}