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
When a number gets assigned to a variable that already has a value __________?
Aleksandr-060686 [28]
A already assigned variable cannot be assigned twice You can make the variable change over to a new one or call a whole new one to assign one without a value or It might be possible to do v=n (v is variable and n is number / value)
3 0
3 years ago
What specific database stores local user accounts on local computers, and allows users to sign in to and access resources only o
Yuki888 [10]

Answer:

The Security Account Manager

Explanation:

The Security Account Manager (SAM), This is a database file found in Windows Operating Systems.... Windows XP, Windows Vista, Windows 7, 8.1 and 10 that stores users' passwords. It can be used to authenticate local and remote users. It is  an important and vital component of how Windows stores passwords locally on the computer.

5 0
3 years ago
When formatting numbers with the Comma Number Format tool, the numbers are formatted with _________.
irina [24]

Answer:

2 decimal places

Explanation:

5 0
2 years ago
What is the output of the following program segment?
marissa [1.9K]

Answer:

5

Explanation:

The operator 'x++' is called the post increment operator, it is assign first and then increment.

The operator '++x' is called the pre increment operator, it is increment first  and then increment.

So, both are increment operator which increment the value by one.

initially the value of x is zero,

++x increase the value to 1 and than assign to x.

then, x++ it assign to x first then increment by 1 means x=2

and so on.....

Their are five increment operator are used. so, the result is 5.

3 0
3 years ago
What are the different methods of enhancing/decorating<br> bamboo product​
Zepler [3.9K]

Explanation:

Methods of this technique include glueing, chemical gilding, and electroplating.  Staining is used to color wood to give an illusion of texture. This may come in two varieties.

7 0
3 years ago
Other questions:
  • In what scenario should dhcp servers also be active dhcp clients?
    8·1 answer
  • Can a computer will work more efficiently if you perform disk optimization
    9·1 answer
  • Important tools used in the _____ phase of the DMAIC process include a project charter, a description of customer requirements,
    10·1 answer
  • To find out how much ram is installed on a machine, in windows go to the user: a power ______ is a part inside a computer case t
    6·1 answer
  • 1. provide at least 3 properties and 3 methods of the object computer.
    8·1 answer
  • What’s an example of software?
    6·2 answers
  • How can you assess a website for currency?
    14·2 answers
  • Ling has configured a delegate for her calendar and would like to ensure that the delegate is aware of their permissions. Which
    13·2 answers
  • Software licensed as proprietary
    11·2 answers
  • How do you open an application on the macOS?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!