Java – If Then Statement

PREV     NEXT

The statements under the ‘if’ block are executed only when the condition evaluates to true.

Syntax:

If (condition)


{

//statements

}

Example:


COMPILE & RUN

Output:

a is greater than b
  • Here the value of a is greater than the value of b, thus the statement ‘a is greater than b is printed.
  • Deciding whether to execute the statement(s) or not, depends upon the condition specified. Hence it is called as decision making statement.

if statement’s condition should evaluate only to the boolean values ‘true’ or ‘false’. We can add more than one condition in the same if statement by using && or || operators.

PREV     NEXT

Share this website !!!
Facebook Twitter Linkedin