Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the effect of word war second?

Answered: 1 week ago