EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Videos

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

Explanation of Solution

Program:

File name: “CountWords.java

//Import necessary header files

import java.util.*;

//Define a class named CountWords

public class CountWords

{

    //Define main method

    public static void main(String[] args)

    {

        //Create an object for the Scanner class

        Scanner in = new Scanner(System.in);

        //Declare the variables

        String str;

        char ch;

        int x;

        int count = 0;

        int length;

        //Declare a Boolean variable and initialize the value

        boolean previousCharWasPunc = false;

        //Prompt the user to enter a String

        System.out.print("Enter a string >> ");

        str = in.nextLine();

        //Read the length of the String

        length = str.length();

        //For loop is executed until x exceeds the string length

        for(x = 0; x < length; x++)

        {

            ch = str.charAt(x);

/* If the words are separated by any combination of spaces,

            periods, commas, semicolons, question marks,

            exclamation points, or dashes*/

            if(ch == ' ' || ch == '...

Blurred answer
Students have asked these similar questions
Write an application that counts the words in a String entered by a user. Words are separated by any combination of spaces, periods, commas, semicolons, question marks, exclamation points, or dashes. Figure 7-17 shows a typical execution.
Write an application that prints your initials in large block letters. Make each large letter out of the corresponding characters. Use escape sequences to form your initials. Make sure your initials are the same size as the example below.  Programming language: JAVA Initial: SP
Write a java application for Limpopo’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R250, R220, R150, or R50, accordingly. Display an error message if the user enters an invalid item.
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:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
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:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Files & File Systems: Crash Course Computer Science #20; Author: CrashCourse;https://www.youtube.com/watch?v=KN8YgJnShPM;License: Standard YouTube License, CC-BY
UNIX Programming (Part - 10) The File System (Directories and Files Names); Author: ITUTEES;https://www.youtube.com/watch?v=K35faWBhzrw;License: Standard Youtube License