import java.util.Scanner;
public class Main {
private static int[] digits = new int[10];
public static void splitNumber(int number) {
do {
digits[Math.abs(number % 10)]++;
number /= 10;
} while (number != 0);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int maxOccurs = 0;
int digit = 0;
System.out.print("Enter the first number: ");
int input1 = in.nextInt();
System.out.print("Enter the second number: ");
int input2 = in.nextInt();
System.out.print("Enter the third number: ");
int input3 = in.nextInt();
System.out.print("Enter the fourth number: ");
int input4 = in.nextInt();
splitNumber(input1);
splitNumber(input2);
splitNumber(input3);
splitNumber(input4);
for (int i = 0; i < digits.length; i++) {
if (digits[i] > maxOccurs) {
maxOccurs = digits[i];
digit = i;
} else if (digits[i] == maxOccurs && digit > i) {
digit = i;
}
}
System.out.println("Max = " + digit);
}
}
Comments
Leave a comment