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
Svetllana [295]
4 years ago
11

In Java write a method called wordCount that accepts a String as its parameter and returns the number of words in the String. A

word is a sequence of one or more nonspace characters (any character other than ' '). For example, the call wordCount("hello") should return 1, the call wordCount("how are you?") should return 3, the call wordCount(" this string has wide spaces ") should return 5, and the call wordCount(" ") should return 0.
Computers and Technology
1 answer:
mamaluj [8]4 years ago
5 0

Answer:

// here is code in java.

import java.util.*;

// class definition

class Main

{

   // method that return the number of words in the string

   public static int wordCount(String st)

   {

       /* split the string by space " " delimiter

       and save them into  string array*/

       String[] no_words=st.split(" ");

       // find the length of array

       int len= no_words.length;

       //return the length

       return len;

   }

   // driver function

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // scanner object to read input string

       Scanner s=new Scanner(System.in);

        // string variable

       String str;

       //ask user to enter string

       System.out.print("please enter the string: ");

       // read the string from user

       str=s.nextLine();

       // call the function with string parameter

      int tot_words= wordCount(str);

      // print the number of word in string

      System.out.println("total words in the string is : "+tot_words);

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read a string from user with the help of scanner class object.Call the function

wordCount() with string parameter.Here split the string by space " " delimiter.

Save the words into a string array.Find the length of the array and return it.

Then in the main print the number of words in the input string.

Output:

please enter the string: this string has wide spaces

total words in the string is : 5

You might be interested in
How is your favorite singer and why I will give Brainliest
Lorico [155]

Answer:

Eslabon Armando

His songs hit different ;-;

5 0
2 years ago
Read 2 more answers
// This pseudocode segment is intended to compute the number
Harlamova29_29 [7]

DEBUG01-01

//This pseudocode is intended to describe

//computing the price of an item on sale for 10% off

START

  input origPrice

  discount = origPrice * 0.10

  finalPrice = origPrice - discount

  output finalPrice

STOP

DEBUG01-02

//This pseudocode is intended to compute the number

//of miles per gallon you get with your automobile.

START

  input milesTraveled

  input gallonsOfGasUsed

  milesPerGallon = milesTraveled / gallonsOfGasUsed

     //milesPerGallon is computed using division

  output milesPerGallon

     //miles is misspelled, and the P in milesPerGallon should be uppercase

STOP

  //Program should end with stop

DEBUG01-03

//This pseudocode is intended to describe

//computing the per day cost of your rent

//in a 30-day month

START

  input rent

  costPerDay = rent / 30

     // Comment indicates 30-day month

  output costPerDay

     // output should be costPerDay

STOP

<h3>What is an algorithm?</h3>

An algorithm can be defined as a standard formula which comprises a set of finite steps and instructions that must be executed by a software program, in order to proffer solutions to a problem on a computer, under appropriate conditions.

         

<h3>What is a pseudocode?</h3>

A pseudocode can be defined as a description of the steps that are contained in an algorithm, especially through the use of a plain (natural) language.

<u>Note:</u> The indentation may change due to Brainly's text editor.

Read more on pseudocode here: brainly.com/question/13208346

#SPJ1

<u>Complete Question:</u>

Your downloadable files for Chapter 1 include DEBUG01-01.txt, DEBUG01-02.txt, and DEBUG01-03.txt. Each file starts with some comments (lines that begin with two slashes) that describe the program. Examine the pseudocode that follows the introductory comments, then find and correct all the bugs.

4 0
2 years ago
Can run mobile-style apps in the area known as the start screen, while running traditional software in the more familiar desktop
Travka [436]
The correct answer: Yes, mobile-style apps can run in a personal computer's desktop.

That is possible by means of a desktop application called emulatator. An emulator like Bluestacks allows a personal computer to run mobile-style apps by acting as a virtual drive in the personal computer's harddisk. 

Emulation is successful if the system requirements of the mobile-application is met by the personal computer's system attributes such as Random Access Memory abundance, Random Access Memory speed, Processing speed (in some cases core abundance e.g. core 2) etc. 

Some mobile-applications do not work in the personal computer's desktop, however, if this application requires platform specific functions such as mobile device's network provider etc.
4 0
4 years ago
2. Why do old video games have large pixels and images with jagged edges?
egoroff_w [7]

Answer:

A

Explanation:

cuz yea

3 0
2 years ago
3.1.2 Quiz: What Can Information Technology Do for You? Question 8 of 10 What is one reason why a business may want to move enti
balu736 [363]

Answer:

C. To focus on a global market

Explanation:

Information technology can be defined as a set of components or computer systems, which is used to collect, store, and process data, as well as dissemination of information, knowledge, and distribution of digital products.

An information technology interacts with its environment by receiving data in its raw forms and information in a usable format.

Generally, it is an integral part of human life because individuals, organizations, and institutions rely on information technology and systems in order to perform their duties, functions or tasks and to manage their operations effectively. For example, all organizations make use of information technology and systems for supply chain management, process financial accounts, manage their workforce, and as a marketing channels to reach their customers or potential customers.

Additionally, an information system or technology comprises of five (5) main components;

1. Hardware.

2. Software.

3. Database.

4. Human resources.

5. Telecommunications.

Hence, information technology or system relies on the data it receives from its environment, processes this data into formats that are usable by the end users.

One reason why a business may want to move entirely online is to focus on a global market through the use of social media platforms and networks to reach out to customers in various geographical location.

5 0
3 years ago
Other questions:
  • The term ________ refers to the use of a single unifying device that handles media, internet, entertainment, and telephone needs
    13·1 answer
  • Debugging is not testing, but always occurs as a consequence of testing. <br> A) TRUE<br> B) FALSE
    13·1 answer
  • A ________ is hardware or software that acts as a filter to prevent unwanted packets from entering a network.
    9·2 answers
  • A firewall, when properly implemented, can prevent most attacks on your system.
    11·1 answer
  • You are working on an excel table and realize that you need to add a row to the middle of your table. what is one way to do this
    12·1 answer
  • You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, an int variable nZips
    10·2 answers
  • Describe the best way to deal with a difficult co-worker?
    13·2 answers
  • 15 points. Please give an actual answer and not some random thing. this is not just free points. Correct answer will receive bra
    12·2 answers
  • Difference between automated testing and manual testing
    13·1 answer
  • Information to develop a project network is collected from the.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!