Question

In: Computer Science

write an application that inputs a telephone number as a stringin the form (555) 555_5555....

write an application that inputs a telephone number as a string in the form (555) 555_5555. the application should use string method split to extract the area code as a token. the first three digits of the phone number as a token and the last four digits of the phone number as a token. the seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be printed. Remember that you'll have to change delimiter characters during the tokenization process.

Solutions

Expert Solution

import java.util.Scanner;

public class PhoneNumber {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter phone number: ");
        String phone = sc.nextLine();
        String area_code = phone.split("\\)")[0].substring(1);
        String last_four = phone.substring(9);
        System.out.println("Area code: "+area_code);
        System.out.println("Phone number: "+area_code+last_four);
    }
}

Output:

======


Related Solutions

JAVA 1. Write an application that inputs a telephone number as a string in the form...
JAVA 1. Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be printed....
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the...
Tokenizing Telephone Numbers Write java application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be...
Write a function called tokenizeTelNum that inputs a telephone number as a string in the form...
Write a function called tokenizeTelNum that inputs a telephone number as a string in the form (555) 555-5555. The function should use the function strok to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. The function should convert the area code string to int and...
(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the...
(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the form (555) 555-5555. The program should use function strtok to extract the area code as a token, the first three digits of the telephone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. The program should convert the area-code string to int and convert...
Alphabetic Telephone Number Translator           Many companies use telephone numbers like 555-GET-FOOD so the number is...
Alphabetic Telephone Number Translator           Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2             D, E, and F = 3             G, H, and I = 4             J, K, and L = 5             M, N, and O = 6             P, Q, R, and S = 7            ...
Write an application, Phone Numbers, that creates and prints a random phone number of the form...
Write an application, Phone Numbers, that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output. The phone number has some constraints. Do not let the first three digits contain an 3 or 7 (but do not be more restrictive than that) and ensure that the second set of three digits is not greater than 825. Note that any of the digits can be zero and zeroes should be shown.
Write a Python program, phone.py, that inputs a string of characters which represent a vanity telephone...
Write a Python program, phone.py, that inputs a string of characters which represent a vanity telephone number, e.g., 800-MYPYTHON, and prints the all numeric equivalent, 800-69798466. You should implement this using a loop construct to process each character from left to right. Build a new string that is the all numeric equivalent and then print the string.
Write pseudocode for a function that translates a telephone number with letters in it (such as...
Write pseudocode for a function that translates a telephone number with letters in it (such as 1-800-FLOWERS) into the actual phone number. Use the standard letters on a phone pad
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs...
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs and prints the number of even and odd inputs in the sequence. please explain. Thanks
This is a Java program Problem Description Write an application that inputs five digits from the...
This is a Java program Problem Description Write an application that inputs five digits from the user, assembles the individual digits into a five-digit integer number (the first digit is for one’s place, the second digit is for the ten’s place, etc.) using arithmetic calculations and prints the number. Assume that the user enters enough digits. Sample Output Enter five digits: 1 2 3 4 5 The number is 54321 Problem-Solving Tips The input digits are integer, so you will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT