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
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
Related Questions
Rewrite the following do while program segment using for:
x = 10; y = 20; do { x++; y++; } while (x<=20); System.out.println(x * y );Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even numberWhich of the following are entry controlled loops?
(a) for
(b) while
(c) do..while
(d) switch
- only a
- a and b
- a and c
- c and d