Home » java » Java if else statement

Java if else statement

if else is a selection statement when execution of statement depends upon condition.

Condition specified in if statement is true then the statement associated with if statement are executed otherwise statements of else block is executed.
For example to find the greater among two number we use if else as follows


If Statement

It is not mandatory to use else with if statement


Example To print value if is less than 10


This program will not do any thing if number is greater then 10

Nested if else

if else statement can be used with in another if else statement


Find the greatest among the three numbers

Ladder if – else


It is the combination of if else if statement Here execution of statement depends upon if statement’s condition.
If the condition is true for if or else if block only its associated statement is executed rest of the condition is not checked.
It any condition does not match then else block is executed.

Example show grade of student based on percentage

Managed by MochaHost - Fast & Easy WordPress Hosting