The selection statements have four variations:
- if statement
- if...else statement
- if...else if-...-else statement
- switch...case statement
The selection statements have four variations:
The simple if statement allows executing a certain statement or block conditionally, only when the result of the expression evaluation is true:
if(booelan expression){
//do something
}
Here are a few examples:
if(true) System.out.println("true"); //1: true
if(false) System.out.println("false"); //2:
int x = 1, y = 5;
if(x > y) System.out.println("x > y"); //3:
if(x < y) System.out.println("x < y"); //4: x < y
if((x + 5) > y) { //5: x + 5 > y
System.out.println("x + 5 > y...