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
Dmitrij [34]
3 years ago
11

Imagine the user types in a complete sentence, but we want to read only the first word and place it in the String variable word.

What are the statements that will declare the Scanner object and read the value of word
Computers and Technology
1 answer:
Vladimir [108]3 years ago
8 0

Answer:

import java.util.Scanner;

public class FirstWord {

   public static void main(String[] args) {

       //NOW YOU WANT TO COLLECT INPUTS FROM THE STUDENT OR USER

       //IMPORT THE SCANNER CLASS FIRST  outside your class

       // THEN YOU CREATE AN OBJECT OF THE SCANNER CLASS

       Scanner input = new Scanner(System.in);

       

       //CREATE A VARIABLE TO HOLD THE USER INPUT

       String text = input.nextLine();

       

       //The variable holder will be used to store characters from the for loop

       String holder="";

       

       //Create a for loop that loops through the user's input

       for(int i=0; i<text.length(); i++){

           //As the loop increases, we get the character in the user's input and store them one by one in the variable holder

           holder+=text.charAt(i);

           if(text.charAt(i)==' '){

               //If the loop encounters a space, it means a complete word has been gotten from the user's input

               //Then the break below Breaks the loop, and the loop stops running

               break;

           }

       }

       System.out.println(holder);

}

Explanation:

text.length() returns the length of the sequence of characters present in length

text.charAt(a number) Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

Create a for loop

How does a for loop work?

It collects a starting point, an end point and an increment respectively....all these are passed in as arguments into the for loop

For example, the code above starts from 0, calculates the number of characters in the user's input and sets it as the end point, the loop runs from zero to the length of the text of the user...

Note: i++ in the loop is the increment, it means the loop increases by 1

You might be interested in
Select the statement that best describes the function of the cell wall. O it gives shape to plants cells. O it produces food fro
Maslowich
It’s jelly like fluid surrounds the nucleus
8 0
2 years ago
Which file format would be appropriate for web graphics​
Eddi Din [679]

Answer:

PNG

Explanation:

PNG files can shrink to incredibly small sizes - especially images that are simple colours, shapes, or text. This makes it the ideal image file type for Web graphics.

4 0
2 years ago
If a device does not require a driver, it is _____.
xxTIMURxx [149]

Answer:

(B) plug and play

Explanation:

If a device does not require a driver, it is <u>plug and play</u>. Plug and Play (PnP) is a combination of hardware and software support that enables a computer system to recognize and adapt to hardware configuration changes with little or no intervention by a user, including the loading of appropriate drivers.

7 0
3 years ago
A ________ is a very large general-purpose computer that is capable of performing very many functions as if these are done simul
Soloha48 [4]

Answer:

Mainframe Computer is capable of doing all the functions which are listed in question.

Explanation:

A mainframe is a very large general-purpose computer (usually costing millions of dollars) that is capable of performing very many simultaneous functions, supporting very many simultaneous users, and storing huge amounts of data. A microcomputer is the type of computer you use.

3 0
3 years ago
An incurred cost that cannot be recovered, which is irrelevant for all decisions about the future, is included in the projected
iragen [17]

Answer:

An incurred cost that cannot be recovered, which is irrelevant for all decisions about the future, is included in the projected cost of a project. According to "Thinking Like an Economist," this an example of:<u> Failing to ignore sunk costs</u>

Explanation:

A sunk cost is a cost that cannot be recovered or changed and is independent of any future costs a business may incur. Since decision-making only affects the future course of business, sunk costs should be irrelevant in the decision-making process

3 0
3 years ago
Other questions:
  • What is the difference between pulse code modulation and delta modulation? Provide examples.
    11·1 answer
  • I have been trying to work on this for a while now, and this is on excel
    11·1 answer
  • A large institution, such as a bank, may have thousands of transactions to process in which no user interaction is required; whi
    5·2 answers
  • Write a C++ function using recursion that returns the Greatest Common Divisor of two integers. The greatest common divisor (gcd)
    14·1 answer
  • What was original name<br> whoever answers first gets brainly crown
    9·1 answer
  • What are the 4 features of the month-end review tool in quickbooks online accountant?
    14·1 answer
  • What is the difference between the flip horizontal and the flip vertical option
    8·1 answer
  • How many times do you return after the dateline ?
    12·1 answer
  • Which statement is true about encoding in Python?
    7·1 answer
  • The users, groups, and roles that have access to a server are called ______________________________.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!