Java-if-else-statement .

In this session i have discussed if-else statement in Java .


IF-ELSE-Statement :

If-else statment is a extension of if-statement . 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 else part and the statement inside the else will be executed .

IF-Elese-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=15;
          if(age>=18){
             System.out.println("Valid for vote");
          }
          else{
             System.out.println("Not valid for vote");
          }
      }  
  }
    
    OUTPUT : Not valid for vote
    


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

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


Example : Write a program check the userid and password for login .

 class Hello{ 
         
      public static void main(String args[]){  
          int uid=10,pwd=20;
          if((uid==10) && (pwd==20)){
          
             System.out.println("Login successfull");
          }
          else{
             System.out.println("Invalid userid or password");
          }
      }  
  }
    
    OUTPUT : Login successfull
    

Welcome to AndroidATPoint.

back image                     next image