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
I bought an iPhone 6s Plus with 16gb three days ago and I found out that it s very little space for my liking and I want to exch
Mashutka [201]
You can return it for a refund, however with that money you will need to pay the difference, as they are different models and the 64gb will cost more.
3 0
3 years ago
Why might a scientist chose to do fieldwork instead of a laboratory experiment?
Marina CMI [18]
 In a a fieldwork experiment the scientist experimentally examines an intervention in the real world. A scientist might choose a fieldwork instead of laboratory experiment in order to answer for example some <span>behavioral questions. Often  the best observations are made in the field.</span>
<span>A field experiment is more suitable for investigating a wider range of factors affecting the overall result.</span>

3 0
4 years ago
A notebook computer is set up to take maximum advantage of power saving features including shutting down the display and the har
astra-53 [7]

Answer:

The reason is that the windowing system consumes significantly more memory and virtual memory than the text mode.

Explanation:

The reason behind the occurrence of this is that the windowing system consumes significantly more memory and virtual memory than the text mode. As a result, this reduces the likelihood of the hard disk becoming inactive for long enough for it to be powered down by itself with no direct human control, i.e. automatically.

6 0
3 years ago
Consider the following recursive method: public int someFun(int n) { if (n &lt;= 0) return 2; else return someFun(n-1) * someFun
Stella [2.4K]

Answer:

(a) someFunc(3) will be called 4 times.

(b) For non negative number n someFunc method calculates 2^2^n.

Explanation:

When you call someFunc(5) it will call someFunc(4) two time.

So now we have two someFunc(4) now each someFunc(4) will call someFunc(3) two times.Hence the call to someFun(3) is 4 times.

someFunc(n) calculates someFunc(n-1) two times and calculates it's product.

someFunc(n) = someFunc(n-1)^2..........(1)

someFunc(n-1)=someFunc(n-2)^2..........(2)

substituting the value form eq2 to eq 1.

someFunc(n)=someFunc(n-2)^2^2

       .

       .

       .

       .

= someFunc(n-n)^2^n.

=2^2^n

2 raised to the power 2 raised to the power n.

3 0
3 years ago
Which city is the largest within the Andean and midlatitude countries? A. Buenos Aires, Argentina B. La Paz, Bolivia C. Santiago
Westkost [7]
My best guess would be either B. or C. 
Hope I helped:)
8 0
3 years ago
Read 2 more answers
Other questions:
  • 3.34 LAB: Mad Lib - loops in C++
    14·1 answer
  • In what era did plants begin to flourish?
    9·1 answer
  • What is the code for loading image in matlab
    15·1 answer
  • Which quality of service (QoS) mechanism provided by the network does real-time transport protocol (RTP) rely on to guarantee a
    13·1 answer
  • In which of the following careers must one learn and use programming languages?
    12·1 answer
  • Which of the following are engine features of 2018 TITAN XD Diesel but not of 2018 TITAN XD Gas?
    13·1 answer
  • Write the definition of a class Counter containing:
    5·1 answer
  • what are examples of conditional formatting tools? check all that apply. color scales, icon sets,data bars,cell styles,themes
    8·1 answer
  • HELP PLEASE!!!! If you are continually building, reviewing, correcting a model of your system, and incrementally adding to the s
    9·1 answer
  • Write a C program to find the sum of 10 non-negative numbers entered by user​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!