Computer Applications
Write a program to take a number from the user as input. Find and print the largest digit of the number.
Example:
Sample Input: 748623
Largest digit: 8
Java
Java Iterative Stmts
9 Likes
Answer
import java.util.Scanner;
public class KboatLargestDigit
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Number: ");
int n = in.nextInt();
int l = -1;
while (n != 0) {
int d = n % 10;
if (d > l)
l = d;
n /= 10;
}
System.out.println("Largest Digit = " + l);
}
}Output

Answered By
3 Likes