Java if statement example


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


Updated on: 15-Jun-2020

146 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements