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
The New option is found in the ...............tab.​
morpeh [17]

in your notes books and in your vopy

3 0
3 years ago
Read 2 more answers
Describe who was Alan Turing in 100 words.<br> First to answer will get brainliest.
NNADVOKAT [17]

Answer:

Alan Turing, in full Alan Mathison Turing, (born June 23, 1912, London, England—died June 7, 1954, Wilmslow, Cheshire), British mathematician and logician who made major contributions to mathematics, cryptanalysis, logic, philosophy, and mathematical biology and also to the new areas later named computer science, cognitive science, artificial intelligence, and artificial life.

Explanation:

Turing was a founding father of artificial intelligence and of modern cognitive science, and he was a leading early exponent of the hypothesis that the human brain is in large part a digital computing machine.Alan Turing was one of the most influential British figures of the 20th century. In 1936, Turing invented the computer as part of his attempt to solve a fiendish puzzle known as the Entscheidungsproblem.

5 0
2 years ago
Fordham3 Hardware is known for its consensus buying center culture. Recognizing this corporate culture, someone attempting to se
balandron [24]

Answer: (c) focus exclusively on the head of the buying center.

Explanation:

As Fordham3 Hardware is known for its consensus buying center culture, so someone attempting to sell to Fordham3 should focus exclusively on the head of the buying center.

8 0
3 years ago
Which of the following statements is CORRECT? a. Multiple IRRs can occur only if the signs of the cash flows change more than on
BigorU [14]

Answer: i think the answer is

a. Multiple IRRs can occur only if the signs of the cash flows change more than once.

Explanation:

3 0
3 years ago
To format a picture to look like a sketch or a painting you can add a(an)
Arisa [49]

Answer:

C(reflection effect)

Explanation:

reflection effect

8 0
2 years ago
Other questions:
  • You have found statistics on the Internet that you would like to use in your speech.
    6·1 answer
  • Which term is used to describe a password-protected, encrypted data file that verifies the identity of the sender of a message?
    8·1 answer
  • What is the unit used to describe the intensity of sound?
    5·1 answer
  • Amazon Web Services and Microsoft Azure are some of the most widely used _______.
    7·1 answer
  • Ports that are generally used to establish outbound connections are known as ___ ports.
    14·1 answer
  • Combining two or more cells to make one is called​
    8·1 answer
  • Write a program that reads in an integer, and breaks it into a sequence of individual digits. Display each digit on a separate l
    14·1 answer
  • Chris needs to modify the default bullets that are used in a nonnumbered list in Word.
    12·2 answers
  • Write a format operation that builds a string for the float variable amount that
    11·1 answer
  • Your network uses a network address of 137. 65. 0. 0 with a subnet mask of 255. 255. 0. 0. How many ip addresses are available t
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!