Tutorialslot.com

youtube facebook twitter gmail pinterest

Java Nested if

It consists of many if,if-else and if-else-if statements associated together. It helps in evaluating many "if" conditions.

Syntax
if(condition)
{
   if(condition)
   {
     statements;
   }
   else
   {
     statements;
   }
else
{
   if(condition)
   {
     statements;
   }
   else
   {
     statements;
   }
}

Example:

public class Nestedif
{
  public static void main(String args[])
  {

  int maths=90;

  int physics=43;

  if(maths>50)
   {

     if(physics>50)
    {
     System.out.println("Hi, You passed the Examination");
    }
     else
    {
     System.out.println("Hi,You passed the Maths Examination only");
     }
    }
     else
     {
     if(physics<50)
    {
     System.out.println("Hi,Sorry you are fail");
    }
    else
    {
     System.out.println("Hi, You passed the physics Examination");
    }

    }
  }
}

Output:
Hi,You passed the Maths Examination only



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