-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolstructures.java
57 lines (44 loc) · 1.56 KB
/
controlstructures.java
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
/**
* @author arieldanon
* @version 8 Feb 2024
* This will demo different control structures that we worked on in class
*/
public class controlstructures {
//Declare Main Method
public static void main(String[] args){
//Sequence Structure
// System.out.println("This line will print first");
// System.out.println("This line will print second");
// Selection Structure
// int temp = 73;
// if less than 25 degrees: winter jacket
// if less than 45 degrees: light coat
// if less than 65 degrees: wear a fleece
// if less than 80 degrees: wear short sleeves
// if greater than 80 degrees: wear shorts
// if (temp < 25) {
// The first case
// System.out.println("Wear a winter jacket");
// } else if (temp < 45){
// The second case
//System.out.println("Wear a light coat");
//} else if (temp < 65){
// The third case
//System.out.println("Wear a fleece hoodie");
//} else if (temp < 80){
// The fourth case
// System.out.println("Wear short sleeves");
// } else {
// Fifth case , using else
// System.out.println("Wear shorts");
// Iteration Structure
//declare control variable
int counter = 1;
// while loop with the termination condition
while (counter < 10) {
System.out.println(counter);
// increment the control variable
counter += 1;
}
}
}