Java if statement example

Java Programming Java8Java Technologies Object Oriented Programming

Flow Diagram



If the boolean expression evaluates to true, then the if a block of code will be executed, otherwise else block of code will be executed.

Example

 Live Demo

public class Test {
   public static void main(String args[]) {
      int x = 30;
      if( x < 20 ) {
         System.out.print("This is if statement");
      } else {
         System.out.print("This is else statement");
      }
   }
}

Output

This will produce the following result −

This is else statement


raja
Published on 03-Feb-2018 20:40:52
Advertisements