-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow_control.java
More file actions
69 lines (50 loc) · 1.47 KB
/
flow_control.java
File metadata and controls
69 lines (50 loc) · 1.47 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
// Import package
package flow_control;
// Flow control class
public class flow_control {
// Main function
public static void main(String[] args) {
// Declare variables
int x = 1, y = 2, z = 3, countdown = 10;
// Output variables
System.out.println("x is equal to " + x);
System.out.println("y is equal to " + y);
System.out.println("z is equal to " + z + "\n");
// If/else to check size
if(x > y && x > z) {
System.out.println("x is greater than y and z\n");
} else if(y > x && y > z) {
System.out.println("y is greater than x and z\n");
} else if(z > x && z > y) {
System.out.println("z is greater than x and y\n");
} else {
System.out.println("Two or more of the values are equal.\n");
}
// While statement
while(countdown >= 0) {
// Output current number
System.out.println(countdown);
// Decrement variable
countdown--;
}
// Print "Blast-off!"
System.out.println("Blast-off!\n");
// Demonstrate for loop
for(int i = 0; i <= 10; i++) {
// Output number
System.out.println(i);
}
// Print "Ready or not, here I come!"
System.out.println("Ready or not, here I come!\n");
// Nested for loop to print stairs
for(int j = 0; j <= 10; j++) {
// Print a line
for(int k = 0; k <= j; k++) {
// Print a J
System.out.print("J");
}
// Advance to next line
System.out.println();
}
}
}