-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIf & Else.java
More file actions
44 lines (39 loc) · 1.28 KB
/
If & Else.java
File metadata and controls
44 lines (39 loc) · 1.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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
boolean HasCar = false;
if(HasCar) {
System.out.println("There is a car");
} else {
System.out.println("No car");
}
byte x = 45, y = 55;
if(x >= y) {
System.out.println("Syntax Custom Error");
} else if(x < y) {
System.out.println("x(45) < y(55)");
}
else {
System.out.println("What else can be here?");
}
short a = 149, b = 615;
if(a >= b) {
System.out.println("Syntax Custom Error");
} else if(a < b) {
System.out.println("x(45) < y(55)");
}
// More practic use of If & Else
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your age: ");
byte age = scanner.nextByte();
System.out.print("Enter your password: ");
String pass = scanner.nextLine();
if (age >= 16 && pass.equals("123")){
System.out.println("Welcome");
} else {
System.out.println("Access declined");
}
//also possible without else (only if & else if)
//we can put in if another if or in else if another else if
}
}