java nested if statements code example

Example 1: else if java

else if statement is used to specify new condition if first condition is false.
Syntax:

if(condition1)
{
   // execute if condition1 is true
}
else if (condition2)
{
   // execute if condition2 is true
}
else if (condition3)
{
   // execute if condition3 is true
}
else
{
   // execute if conditions 1, 2 and 3 becomes false
}

Example 2: nested if statement in java

if(something){
	if(somethingElse){
    	doSomething();
    }//else (if) block possible here
}//else (if) block possible here

Tags:

Java Example