Tutorialslot.com

youtube facebook twitter gmail pinterest

If-else-if in java

It involves in evaluating many conditions.When condition in "if" is true it will be executed otherwise statementsin else-if part will be executed but when conditions in both "if" and "else" are not true then statements in "else"part will be executed.

Syntax:
if(condition1)
   {
    Statement1;
  }
else if(condition2)
  {
     Statement2;
   }
else
   {
     Statement3;
  }

Example:
public class ifelseif
{

   public static void main(String[] args)
   {
     int j = 108;

     if(j > 150)
       System.out.println("j is greater than 150");
    else if(j > 100)
        System.out.println("j is grater than 100");
     else
       System.out.println("j is lesser than 100");
   }
}

Output:
j is greater than 100



Advertisement Powered By Google Adsense






IF YOU LIKE THIS TUTORIALS PLEASE SHARE

Share on whatsapp

POPULAR TAGS

Java java tutorials learn java java programming tutorial learn java online learning java professionals tutorials Multithreading Generics Object Oriented Language Methods Polymorphism Inheritance