Java If Statement

thumbnail

If statement in Java is used to control the flow of the program on some condition. If the expression evaluated to true then some statement code block is executed; otherwise, it will get skipped.

The basic format in If Statement:

Syntax:

if(test_expression) {

statement 1;

statement 2;

...

}

Example of a Java Program to show If statement codes

Example 1:

public class SampleIfStatement{

   public static void main(String args[]){
      int valueA=70, valueB=100;

      if(valueB>valueA)
         System.out.println("valueB is greater");
      }
}

Example 2:

public class SampleIfStatement{

   public static void main(String args[]){
      int valueA=90, valueB=50;

      if(valueA>valueB)
         System.out.println("valueA is greater");
      }
}
Back To Top