Maximum Digit in Number

Given a number the task is to find the maximum digit present in that number.

Example: Consider a number 4612. The program should output maximum digit ‘6’ against this number.

Java
import java.util.*;
public class MaxDigit
{
    public static void main(String args[])
    {
        int n=0,r=0,max=0;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        n= sc.nextInt();
        while(n>0)
        {
            r=n%10;
            if(r>max)
            {
                max=r;
            }
            n=n/10;
        }
        System.out.println("Largest digit: "+max);
    }
}
Java