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
Write an application that determines whether a phrase entered by the user is a palindrome. A palindrome is a phrase that reads the same backward and forward without regarding capitalization, spaces or punctuation. And it will allow the user to enter as many phrases as he likes after each iteration.
Using C# Language and Visual Studio.Create a guessing game that shows hint everytime you guess the correct  letter using ArrayList and StringBuilder. FOR EXAMPLE  THE WORD IS MATH IF THE PLAYER GUESS THE RIGHT LETTER SHOW THE RIGHT LETTER  FOR EXAMPLE HE GUESSED THE RIGHT LETTER "A" THE OUTPUT MUST SHOW YOU GUESS THE CORRECT LETTER  _A_ _
Using C# create a console app doing the following Write a method that takes two integers and displays their sum. Write a method that takes five doubles and returns their average. Write a method that returns the sum of two randomly generated integers. Write a method that takes three integers and returns true if their sum is divisible by 3, false otherwise. Write a method that takes two strings and displays the string that has fewer characters. Write a method that takes an array of doubles and returns the largest value in the array. Write a method that generates and returns an array of fifty integer values. Write a method that takes two bool variables and returns true if they have the same value, false otherwise. Write a method that takes an int and a double and returns their product. Write a method that takes a two-dimensional array of integers and returns the average of the entries.
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
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