-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson4IfStatements.java
More file actions
70 lines (56 loc) · 2.28 KB
/
Lesson4IfStatements.java
File metadata and controls
70 lines (56 loc) · 2.28 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
70
public class Lesson4IfStatements {
public static void main(String []args){
//NB WHEN TESTING A CONDITION USE DOUBLE EQUAL SIGN IE (==)this is great for integers
// OR YOU CAN REPLACE THIS WITH [.equals("the string")]
// if statements => performs aBLOCK OF CODE WHEN A CONDITION IS TRUE
// THE CONDITION IS A BOOLEAN IE.IT CAN BE TRUE OR FALSE
/* if(CONDITION){
STATEMENT
}
*/
int age=10;
String weather="sunny";
if(weather.equals("sunny")){
System.out.println("its sunny today.put 0n some light clothes and sunglasses for style");
}
/*
if... else
when the if condition is wrong the else block is executed instead
syntax: if(condition){
statement;
}else{
statement;}
*/
System.out.println("######################################");
System.out.println("this is the result of if---else statement");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
weather ="cloudy";
if (weather.equals("sunny")){
System.out.println("its sunny today.put 0n some light clothes and sunglasses for style");
}else{
System.out.println("hey its not sunny try carrying something heavy today");
}
/*
//if-else-if
It checks multiple conditions in sequence, the first true condition's block is executed.
if(condition){
statement
} else if(condition){
statement
}else if(condition){
statement
}
*/
System.out.println("#################################");
System.out.println(" output of the if-else-if statement");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
weather ="rainy";
if(weather.equals("sunny")){
System.out.println("its sunny today.put 0n some light clothes and sunglasses for style");
} else if(weather.equals("cloudy")){
System.out.println("its cloudy today.Carry some clothes just in case");
}else if(weather.equals("rainy")){
System.out.println("its Rainy today!!Put on a rain coat don't forget your umbrella");
}
}
}