Wednesday, 4 November 2020

Nested if....... else Statement in JAVA

 

 

 

Nested if....... else Statement :-

 

 

It  is always  legal to nest  if -else  statements which  means we can  use one if or  else if  statement  inside another if  or  else  if statement.


 The  syntax for a nested if .....else is as follow :


if(Boolean _expression  1)

 {

     //Executes   when the Boolean  expression 1 is true

    

     if(Boolean _expression  2)

      {

          //Executes when the Boolean  expression  2 is true

        }


 }




We can nest  else  if .....else in the similar way  as we  have nested if statement.


Example :-


public class Test 

{

    public static void main(String  args[])

    {

        int x = 30;

        int  y = 10;

         if(x == 30)

            {

                 if(y == 10)

                  {

                       System .out.print("X = 30 and Y = 10");


                    }


               }

       }

 }



OUTPUT :-

X = 30 and Y = 10


 



No comments:

Post a Comment

Student Marks Calculation app using java

      import javax.swing. *; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class Student { private J...