Computer Science, asked by Rifa48, 11 months ago

Write a program in Java to find the largest among three numbers without && operation but using nested if else statement.​

Answers

Answered by amannishad0512p5zxh6
10

class Greatest

{

public static void main (int a,int b,int c)

{

if(a>b)

{

if(a>c)

{

System.out.println("a is greatest");

}

}

else if(b>a)

{

if(b>c)

{

System.out.println("b is greatest");

}

}

else

System.out.println("c is greatest");

}

}

Hope it will help you.

Mark me brainlest.

And follow me for more java related doubts.


amannishad0512p5zxh6: mark me
amannishad0512p5zxh6: brainy
Answered by suneelgoli
3

Answer:

class JavaExample{

  public static void main(String[] args) {

     int num1 = 10, num2 = 20, num3 = 7;

     if(num1 >= num2) {

  if(num1 >= num3)

 /* This will only execute if conditions given in both the if blocks are true, which means num1 is greater than num2 and num3  */

 System.out.println(num1+" is the largest Number");

  else

        /* This will only execute if the condition in outer if is true and condition in inner if is false. which means num1 is grater than num2 but less than num3. which means num3 is the largest  */

 System.out.println(num3+" is the largest Number");

     }

     else {

  if(num2 >= num3)

 /* This will execute if the condition in outer if is false and inner if is true which means num3 is greater than num1 but num2 is greater than num3. That means num2 is largest */

 System.out.println(num2+" is the largest Number");

  else

 /* This will execute if the condition in outer if is false and inner if is false which means num3 is greater than num1 and num2. That means num3 is largest   */

 System.out.println(num3+" is the largest Number");

     }

  }

}

Output:

20 is the largest Number

Similar questions