Tuesday, 24 July 2012

If statement Example


/*
  If statement Example
  This Java Example shows how to use if statement in Java program.
*/

public class SimpleIfStatementExample {

  public static void main(String[] args) {
 
    /*
     * If statement is used to execute an action if particular condition is true.
     * Syntax of if statement is,
     *
     * if(<condition>)
     *   <statement>
     *
     * while <condition> is a boolean expression, and statement is a valied java
     * statement which will be executed if <condition> is true. To use multiple
     * statements, enclose them in a block.
     *
     */
   
     boolean blnStatus = true;
   
     if(blnStatus)
       System.out.println("Status is true");
  }
}

/*
Output would be
Status is true
*/

No comments:

Post a Comment