1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Andrew [12]
3 years ago
10

Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String me

thod 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 will have to change deliminator characters during the tokenization process.
Computers and Technology
1 answer:
Scilla [17]3 years ago
8 0

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);

}

}

You might be interested in
When you take action independent of direct instruction, you are showing _____.
ozzi

Answer:

Option A, initiative

Explanation:

Initiation is an art of performing an act or task by self motivation rather on command or instruction from anyone.

Insubordination is incorrect as here there is no mentioning of disobeying seniors or authority

Also, courage and power means having strength to perform any task. Here action is performed without any instruction and it in no sense signifies a brave deed.

Hence, option A is correct

8 0
3 years ago
A 30V battery maintains a current through a 10 Ω Resistor. What is the current flow through the resistor?
Troyanec [42]

Answer:

3 amps

Explanation:

because as per ohm's law. "electric current is proportional to voltage and inversely proportional to resistance"

7 0
3 years ago
You cannot be everywhere at once, but your freedom allows you to
Kay [80]
This type of freedom is called dreaming
7 0
3 years ago
Why a design that doesn't fail initially fails after some time/use? identify at least 3 such mechanisms?
alina1380 [7]
Runs out of memory
has uninitialized    variables
uses  undefined behaviour

4 0
3 years ago
Read carefully, is it a he or she?
Tasya [4]
I think there's a typo in the question, otherwise they probably meant a 'she', since the name is Maureen.

Also, the answer is Personal hygiene and grooming.
6 0
3 years ago
Read 2 more answers
Other questions:
  • Identify and explain the three tiers of web-based applications.
    15·1 answer
  • All digital images are made up from varying rectangles of color, called _____________.
    6·2 answers
  • An indicator is a comprehensive analysis of critical information
    8·1 answer
  • 5.
    6·1 answer
  • As Alexa types a message, Outlook autosaves the message at various points. In which folder is the message located if Alexa wants
    15·2 answers
  • Practice problems on functions. Write C function(s) to carry out the specified tasks. For each problem, also write the suggested
    15·1 answer
  • Public static double secret(int first, double second)
    6·1 answer
  • Impact of information technology in the society​
    11·1 answer
  • Need answer Asap!!!! Which file type is the best choice if the image will be made into a billboard?
    12·1 answer
  • How much would it cost to get the screen replaced on a Moto G7?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!