JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
9th Edition
ISBN: 9780357616673
Author: FARRELL
Publisher: CENGAGE L
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
Manhattan distance
Aiwhat cost from Oradea to Goal which Eforie us A* Algorithm G(n)+H(n) last what ıs the cost
What is the SELECT statement? give one reference with your answer What is a URL and what is it used for? give one reference with your answer  What is e-mail, and what are its advantages? Give one reference with your answer
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