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
Helen [10]
4 years ago
13

Write a program called telephone.java that prompts the user to enter their phone number using the specific format: (xxx) xxx-xxx

x. The program should check whether the input entered is valid. The program must also check for the parenthesis () for the area code (the first three numbers). Example: (702)892-0516 would be correct but 702-892-0516 would not be correct. Example: Enter your phone number: 702-908-1333. 702-908-1333 is a NOT a valid phone number as there are no parenthesis (). Another example: Enter your phone number: (70 –290-8133 (70—290-8133 is NOT a valid phone number. If the entered telephone number is valid the program should return a statement that says the phone number is valid.
Computers and Technology
1 answer:
djverab [1.8K]4 years ago
8 0

Answer:

Following are the program in the Java Programming Language.

//import package scanner class

import java.util.Scanner;

//define class

public class telephone {

//define main method

public static void main(String[] args) {

//set object of the scanner class

Scanner sc = new Scanner(System.in);

//print message

System.out.println("Enter tele-phone no. using this format: (xxx)xxx-xxxx: ");

//get input from the user

String phn = sc.next();

//check length of phone number is equal to 13

if(phn.length() == 13) {

//check phone no. containing parentheses

if(phn.charAt(0) == '(' && phn.charAt(4)==')' && phn.charAt(8) == '-') {

//initializing the values

String num1 = phn.substring(1,4);

String num2 = phn.substring(5,8);

String num3 = phn.substring(9);

//check the following input is numeric or not

if(num1.matches("[0-9]+") && num2.matches("[0-9]+")&& num3.matches("[0-9]+")) {

//then, print valid message

System.out.println("Given phone number is valid");

}

//otherwise

else {

//print invalid message

System.out.println("Given phone number is invalid");

}

}

//otherwise

else {

//print invalid message

System.out.println("Given phone number is invalid");

}

}

//otherwise

else {

//print invalid message

System.out.println("Given phone number is invalid");

}

}

}

Explanation:

Following are the desciption of the program

  • Declared a class telephone
  • Read a input phone number in phn variable of string type.

Check the following condition of phone number

  •  if "phn"=="13" then it check for the parenthesis and number is valid otherwise phn number is invalid .
You might be interested in
Which of the following is used by a seller to deceive a buyer? a. bait and switch b. contest c. display d. introductory offer
notka56 [123]
The answer to this question is A. bait and switch.
4 0
4 years ago
Read 2 more answers
George wants to edit the font of the title text in his presentation. Where can he find the option to edit it?
liberstina [14]
The answer is the answer choice D
4 0
3 years ago
Read 2 more answers
One common advantage of a long-term investment is
Marizza181 [45]

Answer:

bitcoin

Explanation:

8 0
3 years ago
To remedy the lack of procedural functionality in SQL, and to provide some standardization within the many vendor offerings, the
MrRa [10]

Answer:

The correct answer is True.

Explanation:

The SQL: 1999 standard calls a Boolean type, but many commercial SQL servers (Oracle Database, IBM DB2) do not support it as a valid column type, a variable type or to allow it in the result set. Microsoft SQL Server is one of the few database systems that correctly supports Boolean type values using its "BIT" data type. Each 8 BIT fields occupy a full byte of disk space. MySQL interprets "BOOLEAN" as a synonym for TINYINT (8-bit signed integer). PostgreSQL provides a Boolean type of standard compliance.

5 0
3 years ago
In a PivotTable, how can a field of data be hidden from the viewer but still be active in calculations made by Excel’s formulas?
Nuetrik [128]
C. The user can select a cell in that field and click “collapse entire field” in the options tab. Is probably not right!
5 0
3 years ago
Other questions:
  • My mom works from home selling her craft work online to people all over the world. She can do this from home because we have acc
    11·1 answer
  • A navigation device that transfers packets of data between two or more networks is called a _______
    12·1 answer
  • The article begins with the author mentioning the need to find something from “three years ago”. How long do you see yourself sa
    7·1 answer
  • 5255555555555+55555555555555/1111*99442
    14·2 answers
  • How do you access the dark web? What are the negatives of doing this?
    14·1 answer
  • (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Outpu
    7·1 answer
  • How do web bugs invade a person's privacy?
    7·1 answer
  • _____ involves storing data and running applications outside the company’s firewall. answer grid computing parallel computing cl
    11·1 answer
  • See the lseek_example.c file. Modify the lseek_example.c, such that it reads from an input file (named "start.txt") and will pri
    6·1 answer
  • Why would you choose a mobile device over a laptop? 1-2 sentences.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!