forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfElse.java
More file actions
32 lines (25 loc) · 731 Bytes
/
IfElse.java
File metadata and controls
32 lines (25 loc) · 731 Bytes
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
public class IfElse {
public static void main(String[] args) {
int x = 17;
int n = 18;
if (x > 0) {
System.out.println("x is positive");
}
if (x % 2 == 0) {
System.out.println("x is even");
} else {
System.out.println("x is odd");
}
// look, no braces...bad idea!
if (x % 2 == 0)
System.out.println("x is even");
else
System.out.println("x is odd");
if (x > 0)
System.out.println("x is positive");
System.out.println("x is not zero");
if (x % 2 == 0); { // incorrect semicolon
System.out.println("x is even");
}
}
}