MAKE A PROGRAM TO CHECK WHICH NO. IS GREATER IN 4 NO'S IN JAVA ???
**class u
{
public static void main(String as[])
{
int a,b,c,d;
a=Integer.parseInt(as[0]);
b=Integer.parseInt(as[1]);
c=Integer.parseInt(as[2]);
d=Integer.parseInt(as[3]);
if(a>b)
{
if(a>c)
{
if(a>d)
{
System.out.println("a is greater");
}
else if(d>b)
{
if(d>c)
{
System.out.println("d is greater");
}
else
{
System.out.println("c is greater");
}
}
else
{
System.out.println("b is greater");
}
}
else if(c>b)
{
if(c>d)
{
System.out.println("c is greater");
}
else if(d>a)
{
if(d>b)
{
System.out.println("d is greater");
}
else
{
System.out.println("c is greater");
}
}
else
{
System.out.println("c is greater");
}
}
}
else if(b>c)
{
if(b>d)
{
System.out.println("b is greater");
}
else if(d>b)
{
if(d>c)
{
System.out.println("d is greater");
}
else
{
System.out.println("b is greater");
}
}
else
{
System.out.println("b is greater");
}
}
else if(c>d)
{
if(c>a)
{
System.out.println("c is greater");
}
else
{
System.out.println("c is greater");
}
}
else
{
System.out.println("d is greater");
}
}
}**
import java.util.*;
class FindLargest{
public static void main(String[] args){
int max = Integer.MIN_VALUE;
System.out.println("Enter 4 numbers:");
Scanner input=new Scanner(System.in);
for(int i=1;i<=4;i++){
int num=input.nextInt();
if (num > max) {
max = num;
}
}
System.out.println("Largest Number is: "+max);
}
}
thanks for give to short coding for this question but my friend first anwser for clearly understand a if else condition(NESTED IF CONDITION)