JAVA programs

Program to find greater no between three numbers

In this program we see how to find out greater number between three integers using nested if- else. Nested if  else are statement in other if else statement.  Following program demonstrate use of else-if ladder.

Program

class NestedIfElseDemo

{

            public static void main(String args[])

            {

                        int a=15;

                        int b=10;

                        int c=20;

                        if(a>b)

                        {

                         if(a>c)

                             System.out.println("Value of a is greater than b and c ");

                        else

                            System.out.println("Value of c is greater than a and b ");

                        }

                        else

                        {

                                    if(b>c)

                                    System.out.println("Value of b is greater than c ");

                                    else

                                    System.out.println("Value of c is greater than b ");

                        }

            }

}

When Run The Program Following Output:

Value of c is greater than a and b

Description

In above program we use nested if-else statement which have syntax as follows,

In which inner condition execute if only outer condition is true.

Syntax of nested if-else

if(condition)

{

   // Executes when the conditon is true

   If (condition) {

      // Executes when the Boolean expression 2 is true

   }

}

Releted Programs

© 2017 codewmAll rights reserved.