Question
Write a method that counts the occurrences of each digit in a string using the following header: public static int[] count(String s) The method counts
Write a method that counts the occurrences of each digit in a string using the following header: public static int[] count(String s) The method counts how many times a digit appears in the string. The return value is an array of ten elements, each of which holds the count for a digit. For example, after executing int[] counts = count("12203AB3"), counts[0] is 1, counts[1] is 1, counts[2] is 2, and counts[3] is 2. Only display digits with counts greater than 0. Write a Java program called Counts that prompts the user to enter a string, calls method count, and displays the number of occurrences of each digit in the string.
Thank you in advance!
Here are two sample runs: Enter a string: 23231adbc1234 Digit 1 occurs 2 times Digit 2 occurs 3 times Digit 3 occurs 3 times Digit 4 occurs 1 time Enter a string: 987RTVB34 Digit 3 occurs 1 time Digit 4 occurs 1 time Digit 7 occurs 1 time Digit 8 occurs 1 time Digit 9 occurs 1 timeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started