Computer Science, asked by ArpitaSharmaAS, 11 months ago

Write a java program to find largest of 4 numbers using nested if else..
plzz answer it clearly
plzzzzzzzzzZzzzzzZzzzzzzZzzzzzZzzzzZzzzzZzzzZzzzz ​

Answers

Answered by agrima490
0

public class Largest { public static void main(String[] args) { double n1 = -4.5, n2 = 3.9, n3 = 2.5; if( n1 >= n2 && n1 >= n3) System.out.println(n1 + " is the largest number."); else if (n2 >= n1 && n2 >= n3) System.out.println(n2 + " is the largest number."); else System.out.println(n3 + " is the largest number.");


ArpitaSharmaAS: using nested if else
Answered by Anonymous
2

import java.util.*;

{

public static void main (String args [])

{

Scanner sc=new Scanner (System.in);

System.out.println("enter 4 numbers");

int a=sc.nextInt();

int b=sc.nextInt();

int c=sc.nextInt();

int d=sc.nextInt();

if(!(a==b && b==c && c==d && d==a))

{

if(a>b && a>c && a>d)

{

System.out.println("a is the largest");

}

else if(b>c && b>d && b>a)

{

System.out.println("b is the largest");

}

else if (c>d && c>a && c>b)

{

System.out.println("c is the largest");

}

else if (d>a && d>b && d>c)

{

System.out.println("d is the largest");

}

}

else

{

System.out.println(" all are equal");

}

}


Anonymous: I have used nested if
Anonymous: jus thanks!
ArpitaSharmaAS: yeah
Anonymous: now it's good
Anonymous: thanks for this favour
ArpitaSharmaAS: welcome
ArpitaSharmaAS: plzzz answer my question its in my profile
ArpitaSharmaAS: plzzzzzz
Anonymous: ok
Anonymous: done
Similar questions