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

 

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

Many online forms request a user's phone number including the area code and country 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:
+CC (aaa) xxx-xxxx
where CC is a two digit country code, aaa is the area code and each x is a numeric digit.
Our users will enter an 12 digit number like this:
CCaaaxxxxxxx

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!


convertPhoneNumberWithCC("010123456789") → "+01 (012) 345-6789"
convertPhoneNumberWithCC("013105551212") → "+01 (310) 555-1212"
convertPhoneNumberWithCC("888888888888") → "+88 (888) 888-8888"

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

String convertPhoneNumberWithCC(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