Skip to Content

If statement Example

  1. /*
  2.   If statement Example
  3.   This Java Example shows how to use if statement in Java program.
  4. */
  5.  
  6. public class SimpleIfStatementExample {
  7.  
  8.   public static void main(String[] args) {
  9.    
  10.     /*
  11.      * If statement is used to execute an action if particular condition is true.
  12.      * Syntax of if statement is,
  13.      *
  14.      * if(<condition>)
  15.      *   <statement>
  16.      *  
  17.      * while <condition> is a boolean expression, and statement is a valied java
  18.      * statement which will be executed if <condition> is true. To use multiple
  19.      * statements, enclose them in a block.
  20.      *  
  21.      */
  22.      
  23.      boolean blnStatus = true;
  24.      
  25.      if(blnStatus)
  26.        System.out.println("Status is true");
  27.   }
  28. }
  29.  
  30. /*
  31. Output would be
  32. Status is true
  33. */