If Else statement Example
- /*
- If Else statement Example
- This Java Example shows how to use if else statement in Java program.
- */
- public class SimpleIfElseStatementExample {
- public static void main(String[] args) {
- /*
- * If else statement is used to execute either of two conditions based
- * upon certain condition.
- * Syntax of if else statement is,
- *
- * if(<condition>)
- * statement1
- * else
- * statement2
- *
- * where <condition> is a boolean expression.
- * If <condition> is true, statement1 will be executed, else statement2 will
- * be executed.
- */
- int i = 0;
- if(i == 0)
- System.out.println("i is 0");
- else
- System.out.println("i is not 0");
- }
- }
- /*
- Output would be
- i is 0
- */



