| layout | default |
|---|---|
| title | Simple If |
| parent | Control Statement |
| nav_order | 2 |
| has_children | true |
The Java if statement is used to test the condition. It checks boolean condition: true or false. There are various types of if statement in java.
if statement
if-else statement
if-else-if ladder
nested if statement
The Java if statement tests the condition. It executes the if block if condition is true.
if(condition){
//code to be executed
} Cases:
class Test
{
public static void main(String[] args)
{
int i=10;
int j;
if(i==10)
{
j=20;
}
System.out.println(j);
}
}Status: Compilation Error, Variable j might not have been innitialized.
