♦ Java If Else
♣ About Java If Else
if, else-if, and else are conditional statements.Deterministic decisions can be made through this literals.
♣ Conditionals in Java
Conditionals provide boolean value as output, upon which further comparison can be done.Conditionals occur two compare same Data Types over operators, such as:-
Description | operation |
---|---|
Greater Than | a > b |
Greater Than or Equal to | a >= b |
Less Than | a < b |
Less Than or Equal to | a <= b |
Equal to | a == b |
Not Equal to | a != b |
♣ Example1: If in Java
"if" code block is executed when the corresponding if condition block is holding boolean value true.In this example, .
Example
Input:
Output:
♣ Example2: Else in Java
"else" condition is executed if all prior conditions are false. In this example, . Example
Input:
Output:
♣ Example3: Else-If in Java
"else if" keyword is Java's interpretation as "if the previous conditions were not true, then try current given condition". In this example, . Example
Input:
Output: