JAVA PROGRAMMING-LMS INTEG.MINDTAP
JAVA PROGRAMMING-LMS INTEG.MINDTAP
8th Edition
ISBN: 9781337091503
Author: FARRELL
Publisher: Cengage Learning
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 7, Problem 9PE

Explanation of Solution

Program:

File name: “PhoneNumberFormat.java

//Import necessary header files

import java.util.Scanner;

//Define a class named PhoneNumberFormat

public class PhoneNumberFormat

{

    //Define main method

    public static void main(String args[])

    {

        //Create an object for the Scanner class

        Scanner scanner = new Scanner(System.in);

        //do..while loop

        do

        {

            //Prompt the user to enter a Phone Number

            System.out.print("\nEnter the Phone Number: ");

            String textPhone = scanner.nextLine();

 /*Continue to accept the user input until the user enters 999*/

            if (textPhone.contains("999"))

                break;

            //If the user enters a ten-digit phone number

            if (textPhone.matches("[0-9]+") && textPhone.length() == 10)

            {

                //Print the result

                System...

Blurred answer
Students have asked these similar questions
Code with comments and output screenshot is must for an Upvote. Thank you! Using Java: Create a random 2000-digit number and store it in a file. Read the number from the file and find the smallest number within our larger number that contains at least every digit. For instance,149485420251367 contains every digit, but 94556780231 is a smaller number that contains every digit.
Program62.javaWrite a program that prompts for a full name (first and last) and assigns it to one string. The program then passes the full name to a void method as its sole parameter. The void method should print the first name, on one line, as many times as indicated by the length of the last name. Sample Output (image below)
Write a program that inserts parentheses, a space, and a dash into a string of 10  user-entered numbers to format it as a phone number. For example, 5153458912  becomes (515) 345-8912. If the user does not enter exactly 10 digits, display an  error message. Continue to accept user input until the user enters 999 (see screen shots next slide).
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License