Java if statement

Java Programming Java8Java Technologies Object Oriented Programming

An if statement consists of a Boolean expression followed by one or more statements.

Syntax

Following is the syntax of an if statement −

if(Boolean_expression) {
   // Statements will execute if the Boolean expression is true
}

If the Boolean expression evaluates to true then the block of code inside the if statement will be executed. If not, the first set of code after the end of the if statement (after the closing curly brace) will be executed.

Flow Diagram




Example

Live Demo

public class Test {

   public static void main(String args[]) {
      int x = 10;

      if( x < 20 ) {
         System.out.print("This is if statement");
      }
   }
}

This will produce the following result −

Output

This is if statement.


raja
Published on 03-Feb-2018 20:32:06
Advertisements