Question: Numbers displayed on the screen must be formatted for readabiity. Think of your phone number, or Social Security number and Credit Card. Write a JAVA

Numbers displayed on the screen must be formatted for readabiity. Think of your phone number, or Social Security number and Credit Card. Write a JAVA program that uses a Scanner to take a single user input.

If the user enters 9 characters format it as a Social Security Number. It should appears as 123-45-6789 (must have dashes) If the user enters 10 characters format it as a phone number. It should appears as (123)456-7890 (parentheses around area code and a dash. If the user enters 16 characters format it as a credit card number. It should appears as 1234 5678 9012 3456 (use spaces every 4 digits)

The user must enter input all numbers and the input must have a length of 9, 10 or 16. If not display an appropriate error message.

  • User enters a single input
  • Output is formatted exactly as specified
  • Solutions use printf()
  • Solution handles errors appropriately

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!