Wap in JAVA to input a 4-digit no. and find largest using nested if.

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);
}
}
}
}

}

Certainly! Here's a Java code snippet that takes a 4-digit number as input and finds the largest digit using nested if statements:

```java
import java.util.Scanner;

public class LargestDigit {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter a 4-digit number: ");
int number = scanner.nextInt();

int firstDigit = number / 1000;
int secondDigit = (number / 100) % 10;
int thirdDigit = (number / 10) % 10;
int fourthDigit = number % 10;

int largestDigit = firstDigit;

if (secondDigit > largestDigit) {
largestDigit = secondDigit;
}
if (thirdDigit > largestDigit) {
largestDigit = thirdDigit;
}
if (fourthDigit > largestDigit) {
largestDigit = fourthDigit;
}

System.out.println("The largest digit in " + number + " is: " + largestDigit);
}
}
```

To input a 4-digit number, we use the `Scanner` class to get user input. We then calculate each digit of the number by dividing it by powers of 10 (`number / 1000` gets the first digit, `number / 100 % 10` gets the second digit, and so on).

We initialize the `largestDigit` variable to the value of the first digit, then use nested if statements to compare it with the other digits. If any of the other digits are larger, we update the `largestDigit` variable accordingly.

Finally, we print out the largest digit.

I hope this helps! Let me know if you have any further questions.