Home » java » Java if else statement

Java if else statement

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

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

Output

If Statement

It is not mandatory to use else with if statement

Syntax

Example To print value if is less than 10

Output

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

Syntax

Find the greatest among the three numbers

Ladder if – else

Syntax

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