Javatpoint Logo

91-9990449935

 0120-4256464

Java If-else Statement

The Java if statement is used to test the condition. It returns true or false. There are various types of if statement in java.

  • if statement
  • if-else statement
  • nested if statement
  • if-else-if ladder

Java IF Statement

The if statement tests the condition. It executes the if statement if condition is true.

Syntax:

if statement in java

Example:

Output:

Age is greater than 18

Java IF-else Statement

The if-else statement also tests the condition. It executes the if block if condition is true otherwise else block.

Syntax:

if-else statement in java

Example:

Output:

odd number

Java IF-else-if ladder Statement

The if-else-if ladder statement executes one condition from multiple statements.

Syntax:

if-else-if ladder statement in java

Example:

Output:

C grade