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");
- long fullPhone = keyboard.nextLong();
- // Find area code part
- long areaCode;
- areaCode = fullPhone / 10000000;
- // Find last 4 digits
- long lastFour = fullPhone % 10000;
- //fullPhone = 10000 - exchange;
- // Find exchange part
- long exchange;
- //phoneMinusAreaCode :=
- exchange = (fullPhone - (areaCode * 10000000) - lastFour)/10000;
- // Print original, plus new number all formatted
- System.out.println("Original number entered: " + fullPhone);
- System.out.println("Phone number formatted: ("+ String.format("%03d", areaCode) + ")" + String.format("%03d", exchange) + "-" + String.format("%04d", lastFour));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement