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]
3 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]3 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
You need to know the MAC address of a Windows 8 computer. How can you accomplish this?
Gre4nikov [31]

1.press window key + R

2.type cmd and press enter

3. write "ipconfig /all" without quotes and press enter

4. look for physical address word

that's your Mac address

6 0
3 years ago
How to copy and paste using keyboard onchromebook?
Diano4ka-milaya [45]
The copy combination is "ctrl+c". Highlight the text, go to where you want to paste it to, and use the combinations "ctrl+v".
5 0
3 years ago
The smallest unit of time in music called?
zmey [24]

Answer:

Ready to help ☺️

Explanation:

A <em>tatum</em> is a feature of music that has been defined as<u> the smallest time interval</u> between notes in a rhythmic phrase.

7 0
3 years ago
Read 2 more answers
The text help readers understand the relationship between gender and sports?THESE PUMPKINS SURE CAN KICK!
AleksAgata [21]

Answer:

What's the question?????I don't understand

4 0
3 years ago
When programming, which of the following is true of the editor?
OLEGan [10]

Answer:

The correct answer is It is a program that checks for grammatical errors.

Explanation:

In programming, when we want to check that our grammar is correct, we can use an editor.

This is a program that allows you to correct spelling through a software application. It analyzes the entered text and automatically checks whether it is spelled correctly or not, comparing the words with its internal database.

Given this information we can say that the correct answer is It is a program that checks for grammatical errors.

5 0
3 years ago
Other questions:
  • To find a webpage, the user of a search engine would simply enter a word or phrase in the resource's text box. what is the term
    11·1 answer
  • A digital certificate system: Group of answer choices uses digital signatures to validate a user's identity. is used primarily b
    13·1 answer
  • Create a program in c/c++ which accepts user input of a decimal number in the range of 1 -100. Each binary bit of this number wi
    9·1 answer
  • If two egg cells are fertilized what will happen?
    10·1 answer
  • 16 to 19 year old drivers are how many more times likely to crash? 1.7,2.7,0.7 ,3.7
    12·2 answers
  • Write the correct statements for the above logic and syntax errors in program below.
    12·1 answer
  • Gauthmath https://s.tutorus.xyz/lp/invite?code=GGQGBL​
    13·1 answer
  • 6
    7·2 answers
  • 8. Give regular expressions with alphabet {a, b} for
    6·1 answer
  • Transaction processing systems (TPSs) provide valuable input to management information systems, decision support systems, and kn
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!