Write a program in java to take a number as input then display the highest digit and lowest digit present in it. Use method prototype: void check(int number). The program must use 3-digit and 4-digit numbers and 1-digit and 2-digit numbers are not to be accepted.
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
if (a < 100) {
System.out.println("Please enter more than two digit number!");
} else {
int min = 9;
int max = 0;
int digit;
while (true) {
digit = s % 10;
if (min > digit) min = digit;
if (max < digit) max = digit;
s /= 10;
if (s == 0) break;
}
System.out.println("Min digit: " + min + "\n" +
"Max digit: " + max);
}
}
}
Comments
Leave a comment