//################################################################ // // PhoneNumbers.java // // Sample Run: // // Please enter a 10 digit phone number: 5152945555 // // Debugging Information: // You entered: [5152945555] // // Full : (515) 294-5555 // Local : 294-5555 // Campus : 4-5555 // //################################################################ import java.util.Scanner; public class PhoneNumbers { public static void main (String[] args) { Scanner scan = new Scanner(System.in); // Reads a 10 digit phone numnber (no spaces and no punctuation) System.out.print("Please enter a 10 digit phone number: "); String number= scan.nextLine(); System.out.println("\nDebugging Information:"); System.out.println("You entered: [" + number + "]"); // Extract the area code (first 3 digits) String areaCode = number.substring(0,3); //Extract the next three digits String nextThree = number.substring(3,6); //Extract the last 4 digits String lastFour = number.substring(6,number.length()); // Print the full number System.out.println("\nFull : " + "(" + areaCode + ") " + nextThree + "-" + lastFour); // Print the local number System.out.println("\nLocal : " + nextThree + "-" + lastFour); // Print the campus number System.out.println("\nCampus : " + nextThree.charAt(2) + "-" + lastFour); } }