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
Which item converts a high level language program to low level machine instruction?
vodomira [7]
The compiler translates each source code instruction into the appropriate machine language instruction, an
8 0
3 years ago
50 POINTS<br><br>Question linked in file below.
Ratling [72]

{{5,10,15,20},{25,30,35,40}} is answer where zero is not found.

<u>Explanation:</u>

This program finds zero in giving as arrays of value as a parameter. The program has two loop. One is a row of the array and the other is column loop for each row o an array. For loop is created with a  variable namer row and the loop ends with a length of the array of each row.

In side row for loop col loop is created and loop ends with each row-column length of cells. If data in each cell i.e (row, col)  calue is zero it returns true and the loop is terminated immediately.

In case if the value of the cell doesn’t found zero it never terminates the loop and continuous loop and returns a false value. Find Zero functions accept the two-dimensional array and check whether cell value is zero. If it is zero found return true otherwise it returns false.

7 0
2 years ago
________ is a hybrid version of Ethernet that uses either 10Base-T, 100Base-T, or 1000Base-T.
Vladimir79 [104]

Answer: ANSWER is B I'm pretty sure

Explanation: hope this help

s :)

7 0
3 years ago
Interchanges of ideas in forums and internet news groups are functions of which domain?
Anarel [89]
I believe that the answer to the question provided above is that the  <span>Interchanges of ideas in forums and internet news groups are functions of the information domain.</span>
Hope my answer would be a great help for you.    If you have more questions feel free to ask here at Brainly.
5 0
3 years ago
Which of these categories of computer software can add thousands of dollars to the cost of a computer system?
Radda [10]
Specialized software. hope this helps
6 0
3 years ago
Other questions:
  • In which type of attack do you get malicious code in links from seemingly reliable websites?
    14·1 answer
  • After installing the processor, if the system begins the boot process and suddenly turns off before completing the boot, the pro
    14·1 answer
  • Which of the following would you not see on a windows 10 start menu?
    6·1 answer
  • Help!!!!!!!!!!!!!!!!!
    11·1 answer
  • Which of the following is NOT one of the four steps preparing for sales forecast ?
    10·1 answer
  • The signature area in a cover letter includes the sender's first and last name, followed by his/her job title (if applicable). *
    13·1 answer
  • Do like TikTok??????
    14·2 answers
  • ................. are used to summarize data (option) (a) report (b) action ​
    12·2 answers
  • Creating a Venn diagram takes specialized computer software.
    15·2 answers
  • Alex has composed a layout with this Image for a magazine. Which rule of composition has Alex applied?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!