Java If-Else Control Statement with Program Examples

In this tutorial post we will study and understand the working of the Java If-Else Conditional Statements.

  • if statement
  • if-else statement
  • if-else-if ladder
  • nested if statement
Java if Statement

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

java if block flow diagram
Syntax:
Program Example –

Output
Positive
Java if-else Statement
The Java if-else statement also tests the condition. It executes the if block if condition is true otherwise else block is executed.
java if else block flow diagram
Syntax:

Program Example –

Output
odd number
Java if-else-if ladder Statement

The if-else-if ladder statement executes one condition from multiple statements. It is used when more than 1 condition is to be checked in relation with the problem.

Java if-else-if ladder Statement

Syntax:
Program Example –
Output
Neither Negative nor Positive
Watch it on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *