The basic format of an if statement : if « Statements « SCJP






if (booleanExpression) {
  System.out.println("Inside if statement");
}

public class MainClass{
    public static void main(String[] argv){
        int x = 1;
        int y = 0;
        int z = 0;
        int a = 0;
        if (x > 3) {
          System.out.println("x is greater than 3");
        } else {
          System.out.println("x is not greater than 3");
        }
        
        //The else block is optional, so you can also use the following:
        
        if (x > 3) {
          y = 2;
        }
        z += 8;
        a = y + x;
    }
}
x is not greater than 3








5.7.if
5.7.1.The basic format of an if statement
5.7.2.The expression in an if statement must be a boolean expression.
5.7.3.Use an else block to execute code that is executed under the conditions that the test returns false.
5.7.4.Use if/else in a nested fashion, refining conditions to more specific, or narrower, tests at each point.