Java-if-statement .

In this session i have discussed if statement in Java .


If statement is a decision making and branching statement in Java . It is following types .

IF statement .

IF-Else statement .

Else-IF Ladder statement .

Nested IF-Else .


IF-Statement :

If statment is a powerful decision making and branching statment . It is allow to evaluate the specified condition if condition is true then the statement inside the if will be executed other wise control transfer to next statement .

If-statement-syntax :

mvc image

Example : Write a java program that check the age for voting .

 class Hello{ 
         
      public static void main(String args[]){  
         int age=19;
         if(age>17){

              System.out.println("Valid for vote");
         }  
      }  
  }
    OUTPUT : Valid for vote
    


Example : Write a java program that check the even number .

 class Hello{ 
         
      public static void main(String args[]){  
       
          int x=4;
          if(x%2==0){

               System.out.println("Even Number");
          }
      }  
  }
    
    OUTPUT : Even Number
    


Example : Write a java program that check the odd number .

 class Hello{ 
         
      public static void main(String args[]){  
       
            int x=5;
            if(x%2!=0){
   
               System.out.println("Odd Number");
          }
      }  
  }
    
   OUTPUT : Odd Number
   

Welcome to AndroidATPoint.

back image                     next image