Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- // set up Scanner for keyboard input
- // Read in phone number
- System.out.println("Enter a 10-digit phone number without spaces");
- String fullPhone = keyboard.next();
- // Find area code part
- String areaCode = fullPhone.substring(0,3);
- // Find last 4 digits
- String lastFour = fullPhone.substring(6);
- //fullPhone = 10000 - exchange;
- // Find exchange part
- String exchange = fullPhone.substring(3,6);
- // Print original, plus new number all formatted
- System.out.println("Original number entered: " + fullPhone);
- System.out.println("Phone number formatted: ("+ areaCode + ")" + exchange + "-" + lastFour);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement