class
{
void d(int n)
{
int a =n/1000;
int b =(n/100)%10;
int c = (n/10)%10;
int d = n%10;
if(a>b)
{
if(a>c)
{
if(a>d)
{
System.out.println("greatest="+a);
}
else
System.out.println("greatest="+d);
}
}
if(b>c)
{
if(b>d)
{
if(b>a)
{
System.out.println("greatest="+b);
}
else
System.out.println("greatest="+d);
}
}
if(c>b)
{
if(c>a)
{
if(c>d)
{
System.out.println("greatest="+c);
}
else
System.out.println("greatest="+d);
}
}
if(d>b)
{
if(d>a)
{
if(d>c)
{
System.out.println("greatest="+a);
}
else
System.out.println("greatest="+c);
}
}
}
}
}
Wap in JAVA to input a 4-digit no. and find largest using nested if.
1 answer