-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareNumbers.java
More file actions
54 lines (32 loc) · 1.07 KB
/
CompareNumbers.java
File metadata and controls
54 lines (32 loc) · 1.07 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
public class CompareNumbers {
public static void main(String[] args) {
int a = 4;
int b = 5;
int result;
// Check if A is greater than B
if (a > b) {
// Subtract if A is greater
result = a - b;
System.out.println("A is greater than B. The result of subtraction is: " + result);
} else {
// Sum if A is less than or equal to B
result = a + b;
System.out.println("A is less than or equal to B. The result of addition is: " + result);
}
int i = 10;
if (i == 10 || i < 15) {
// First if statement
if (i < 15)
System.out.println("i is smaller than 15");
// Nested - if statement
// Will only be executed if statement above
// it is true
if (i < 12)
System.out.println(
"i is smaller than 12 too");
}
else {
System.out.println("i is greater than 15");
}
}
}