id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

abraskin@mbusd.org 2019_units1-4_practice > convertPhoneNumber
prev  |  next  |  chance

Many online forms request a user's phone number including the area code. We need to store the phone number in our user database. Unfortunately, people like to enter their phone number in a particular way that doesn't match the way that we'd like to store it. We will let the user enter the phone number how they like and our method will convert it to the way that we'd like to store it.

Our database wants the phone number formatted like this:
(xxx) xxx-xxxx
where each x is a numeric digit.
Our users will enter a 10 digit number like this:
xxxxxxxxxx
Your method should convert the string of numbers into a new string that is formatted properly for our database.

NOTE: The user's phone number is a String of numeric digits, not an actual number!


convertPhoneNumber("0123456789") → "(012) 345-6789"
convertPhoneNumber("3105551212") → "(310) 555-1212"
convertPhoneNumber("8888888888") → "(888) 888-8888"

...Save, Compile, Run (ctrl-enter)

String convertPhoneNumber(String unformatted) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 200

Copyright Nick Parlante 2017 - privacy