Controls
A control statement in java is a statement that determines whether the other statements will be executed or not. It controls the flow of a program.
If Statement Examples
1. Boolean Variable as Argument
class IfTest {
public static void main(String[] args) {
boolean x = false;
if (x = false) { // This compile as if statement expects boolean value as parameter. This also throws false.
System.out.println("Hello Mercury");
} else {
System.out.println("Hello Venus");
}
}
}
2. Integer Variable as Argument
This doesn't compile as if statement expects boolean value as parameter.
class IfTest{
public static void main(String[] args){
int x = 0;
if(x){ // This doesn't compile as if statement expects boolean value as parameter.
System.out.println("Hello Mercury");
}else{
System.out.println("Hello Venus");
}
}
}