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
What type of windows network model allows all the participants to be represented equally on the network with no single computer
noname [10]
The workgroup as a type of windows network model allows all the participants to be represented equally on the network with no single computer having authority or control over another. The workgroup is peer-to-peer local area network. 
Members of this network group can share files, printers, Internet connection.<span> and other local network resources.</span>
4 0
3 years ago
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space.
Ksenya-84 [330]

Answer:

   while(userNum>=1){

       System.out.print(userNum/2+" ");

       userNum--;

        }

Explanation:

This is implemented in Java programming language. Below is a complete code which prompts a user for the number, receives and stores this number in the variable userNum.

<em>import java.util.Scanner;</em>

<em>public class TestClock {</em>

<em>    public static void main(String[] args) {</em>

<em>    Scanner in = new Scanner (System.in);</em>

<em>        System.out.println("Enter the number");</em>

<em>    int userNum = in.nextInt();</em>

<em>    while(userNum>=1){</em>

<em>        System.out.print(userNum/2+" ");</em>

<em>        userNum--;</em>

<em>         }</em>

<em>    }</em>

<em>}</em>

The condition for the while statement is userNum>=1 and after each iteration we subtract 1 from the value of   userNum until reaching 1 (Hence userNum>=1)

3 0
3 years ago
What type of network is the internet
shtirl [24]

Answer:

The internet is considered as Wide Area Network (WAN).

5 0
2 years ago
What is a good coding site
Helga [31]

Sratch.com

-Agarvated

6 0
2 years ago
Adam is so good at playing arcade games that he will win at every game he plays. One fine day as he was walking on the street, h
klio [65]

Answer:

what the answer chaoices

Explanation:

brainlest me please

3 0
2 years ago
Other questions:
  • This is going to get taken down but I dont care add me on discord cause ima bored<br> -Red-#9847
    12·1 answer
  • Your health insurance company gives you a discount if you wear a fitness-tracking bracelet. After wearing it for a few months, y
    5·1 answer
  • Which best describes rfid technology?
    5·1 answer
  • Csc105 final graded project
    9·1 answer
  • _____________ describes the abstraction of web-based computers, resources, and services that system developers can utilize to im
    9·1 answer
  • (BRAINLIEST QUESTION!!!)
    11·1 answer
  • IRQ 0 interrupt have _______________ priority<br> ? low<br> ? medium<br> ? highest<br> ? lowest
    13·1 answer
  • Unconformities develop when new sedimentary layers accumulate atop old, eroded layers, resulting in a geologic hiatus. Which of
    9·1 answer
  • Question 1 (1 point)
    9·2 answers
  • In _________, the process requests permission to access and modify variables shared with others. a) entry section b) critical se
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!