Question
CharacterFrequency.java import java.util.*; public class CharacterFrequency { public static Scanner kbd; public static void main(String[] args) { kbd = new Scanner(System.in); kbd.close(); } } (Here
CharacterFrequency.java
import java.util.*;
public class CharacterFrequency { public static Scanner kbd; public static void main(String[] args) {
kbd = new Scanner(System.in); kbd.close(); } }
(Here is the starter code)
Write a program that counts the number of times a digit appears in a telephone number.
Your program should begin by creating an array of size 10 that will hold the count for each digit from 0 to 9. Next, read a telephone number from the keyboard. The telephone number should be stored in a String variable. Examine each character in the phone number, and increment the appropriate count in the array. Display the contents of the array.
Note, the user might enter only numbers, as in: 2525551212 or they might enter dashes between the digits, as in: 252-555-1212 or they might enter parentheses and dashes, as in: (252)555-1212 or they might enter parentheses, dashes and spaces, as in: (252) 555-1212
Your program should be able to handle all of these possibilities.
Hint: Ignore any character that isn't a digit. Hint: Use one of the Character methods to determine if a character is a digit or not.
The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:
Please enter a 10-digit telephone number: 252-555-1212 The following is the number of times each digit appears: 0 - 0 1 - 2 2 - 4 3 - 0 4 - 0 5 - 4 6 - 0 7 - 0 8 - 0 9 - 0
Program must use arrays
Program cannot use 'break' statements to exit loops
And please include comments
Step 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