Write a java program to find largest of 4 numbers using nested if else..
plzz answer it clearly
plzzzzzzzzzZzzzzzZzzzzzzZzzzzzZzzzzZzzzzZzzzZzzzz
Answers
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.");
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");
}
}