Advertisement
Guest User

Numbers are stupid in this case

a guest
Sep 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 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.         long fullPhone = keyboard.nextLong();
  14.  
  15.         // Find area code part
  16.         long areaCode;
  17.         areaCode = fullPhone / 10000000;
  18.  
  19.         // Find last 4 digits
  20.         long lastFour = fullPhone % 10000;
  21.         //fullPhone = 10000 - exchange;
  22.  
  23.         // Find exchange part
  24.         long exchange;
  25.         //phoneMinusAreaCode :=
  26.         exchange = (fullPhone - (areaCode * 10000000) - lastFour)/10000;
  27.  
  28.  
  29.         // Print original, plus new number all formatted
  30.         System.out.println("Original number entered: " + fullPhone);
  31.         System.out.println("Phone number formatted: ("+ String.format("%03d", areaCode) + ")" + String.format("%03d", exchange) + "-" + String.format("%04d", lastFour));
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement