forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditional.java
More file actions
33 lines (30 loc) · 764 Bytes
/
Conditional.java
File metadata and controls
33 lines (30 loc) · 764 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
33
/**
* Examples from Chapter 5.
*/
public class Conditional {
public static void main(String[] args) {
printFactsAboutX(5);
printFactsAboutX(6);
printFactsAboutX(0);
printFactsAboutX(-1000);
}
public static void printFactsAboutX(int x){
// first, check whether x is even or odd
if (x % 2 == 0) {
System.out.println(x + " is even");
}
else {
System.out.println(x + " is odd");
}
// then, check whether x is positive, negative, or zero
if (x > 0) {
System.out.println(x + " is positive");
}
else if (x < 0) {
System.out.println(x + " is negative");
}
else {
System.out.println(x + " is zero");
}
}
}