import java.util.*; // Allison Obourn, CSE 142 // Demonstrates tallying. Computes the most frequent digit in a number. public class Tallying { public static void main(String[] args) { System.out.println(mostFrequentDigit(1267654)); } public static int mostFrequentDigit(int n) { int[] counts = new int[10]; while(n > 0) { int digit = n % 10; n = n / 10; counts[digit]++; // counts[digit] = counts[digit] + 1; } int maxIndex = 0; for(int i = 0; i < counts.length; i++) { if(counts[i] > counts[maxIndex]) { maxIndex = i; } } return maxIndex; } }