// Simple program to count the number of times each digit 0-9 // appears in a number provided the user. // Note the use of an array to track the counts. import java.util.*; public class CountDigits { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Enter a positive integer: "); int num = console.nextInt(); int[] counts = digitCounts(num); System.out.println("Digit counts: " + Arrays.toString(counts)); } public static int[] digitCounts(int num) { int[] counts = new int[10]; while (num > 0) { int digit = num % 10; counts[digit]++; num /= 10; } return counts; } }