Asked by Tatvabodh
Wap in JAVA to input a 4-digit no. and find largest using nested if.
Answers
Answered by
Tatvabodh
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);
}
}
}
}
}
{
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);
}
}
}
}
}
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.