Answer:
See explaination
Explanation:
// File: TelephoneNumber.java
import java.util.Scanner;
public class TelephoneNumber
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String inputNumber;
String tokens1[];
String tokens2[];
String areaCode;
String firstThree;
String lastFour;
String allSeven;
String fullNumber;
/* input a telephone number as a string in the form (555) 555-5555BsAt4ube4GblQIAAAAASUVORK5CYII= */
System.out.print("Enter a telephone number as '(XXX) XXX-XXXX': ");
inputNumber = input.nextLine();
System.out.println();
/* use String method split */
tokens1 = inputNumber.split(" ");
/* extract the area code as a token */
areaCode = tokens1[0].substring(1, 4);
/* use String method split */
tokens2 = tokens1[1].split("-");
/* extract the first three digits of the phone number as a token */
firstThree = tokens2[0];
/* extract the last four digits of the phone number as a token */
lastFour = tokens2[1];
/* concatenate the seven digits of the phone number into one string */
allSeven = firstThree + lastFour;
/* concatenate both the area code and the seven digits of the phone number into one full string separated by one space */
fullNumber = areaCode + " " + allSeven;
/* print both the area code and the phone number */
System.out.println("Area code: " + areaCode);
System.out.println("Phone number: " + allSeven);
System.out.println("Full Phone number: " + fullNumber);
}
}