Tutorialslot.com

youtube facebook twitter gmail pinterest

If-else-if ladder in java


It also performs same function as the if-else-if statements but it involves in evaluating many number of conditions.It executes statements which are present in the part where the condition is satisfied unlike other statements are discarded.

Syntax:
if(condition 1)
{
Statement 1;
}
else if (condition 2)
{
Statement 2;
}
.
.
.
.
else if (condition n)
{
Statement n;
}
else
{
Statement;
}

Example:
class Match
{
 public static void main(String[] args)
 {

  int score = 78;
  string g;

   if (score >= 90)
  {
  g = 'we won the match and qualify for finals';

   }
  else if (score >= 80) {
  g = 'we won the match';
   }
   else if (score >= 70)
   {
  g = 'we loss the match and have another chance to win silver';
   }
   else if (score >= 60)
   {
  g = 'we loss the match';
   }
   else
   {
   g = 'we are eliminated';

  }
   System.out.println("Match is " + g);
  }
}

Output:
Match is we loss the match and have another chance to win silver



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