if condition block will be executed, when the condition inside is true. And else will be executed, when the condition inside is false.
Example 1
public class IF_Else_Example1 {
public static void main(String[] args) {
int x = 100;
int y = 150;
if (x > y) {
System.out.println("x is greater");
} else
System.out.println("y is greater");
}
}
Example 2
public class IF_Else_Example2 {
public static void main(String[] args) {
int score = 62;
if (score > 70) {
System.out.println("pass");
} else
System.out.println("fail");
}
}