If Statement


The if statement is used to decide whether a particular block of code will be executed or not based on a certain condition. 

If the condition is true, then the code is executed otherwise not.

Syntax:

if(condition) {

    // block of code to be executed if the condition is true

}

 

Example-

public class IfConcept {

               public static void main(String[] args) {

                              int age = 22;

                              if (age >= 18) {

                                             System.out.println("Eligible for vote");

                              }

               }

}

 

Output: Eligible for vote