Advertisement
Guest User

See, String is coool

a guest
Sep 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner keyboard = new Scanner(System.in);
  8.         // set up Scanner for keyboard input
  9.  
  10.  
  11.         // Read in phone number
  12.         System.out.println("Enter a 10-digit phone number without spaces");
  13.         String fullPhone = keyboard.next();
  14.  
  15.         // Find area code part
  16.         String areaCode = fullPhone.substring(0,3);
  17.  
  18.         // Find last 4 digits
  19.         String lastFour = fullPhone.substring(6);
  20.         //fullPhone = 10000 - exchange;
  21.  
  22.         // Find exchange part
  23.         String exchange = fullPhone.substring(3,6);
  24.  
  25.  
  26.         // Print original, plus new number all formatted
  27.         System.out.println("Original number entered: " + fullPhone);
  28.         System.out.println("Phone number formatted: ("+ areaCode + ")" + exchange + "-" + lastFour);
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement