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
Why might a programmer prefer the top-down approach to programming
faust18 [17]

Answer:

B. SOME PROGRAMMERS THINK this approach makes the software code easier to write and programming tasks easier to understand

Its because they break the computer system into many sub-systems, and then each sub-system is allocated a specific task, then those sub-systems can be broken down further into other sub-systems (this process is called stepwise refinement).

7 0
3 years ago
Read 2 more answers
The part of a rocket engine that allows the combustion gases and flames to leave the rocket engine is the
coldgirl [10]
That would be A: Nozzle
6 0
3 years ago
Note oj cyber security​
dybincka [34]

Answer:

The answer to this question is given below in this explanation section.

Explanation:

                               "cyber security"

cyber security refers to the body of technologies,Processes and practices designed to protect networks,devices,programs and data from attack,damage or unauthorized  access.Cyber security may also be referred to as information technology security.

Importance:

                         Cyber security is important because government financial and medical organization collect process and store unprecedented amounts of data on computer and other devices.A significant portion of that data can be sensitive information,whether that be intellectual property financial data personal information or other type of data for which unauthorized access or exposure could have negative consequences.organizations transmit sensitive data across network and to other devices in the course of doing business,and cyber security describes the discipline dedicated to protecting that information and the systems  use to process or store it.

Challenges of cyber security:

                  For an effective cyber security an organization needs to coordinates its effort throughout its entire information systems.Elements of cyber components all the following:

  • Network security
  • Application security
  • Endpoint security
  • Data security
  • Identity management
  • Database and infrastructure security
  • cloud security
  • Mobile security

Managing cyber security:

            The national cyber security alliance,through recommends a top down  approach to cyber security in which corporate management leads the change in prioritizing cyber security management across all business practices. NCSA advises that companies must be prepaid to response to the inevitable cyber incident restore normal operations,and ensure that company assets and the company reputation are protected.

7 0
3 years ago
How do you activate the Slicer Tools contextual tab?
Strike441 [17]

Answer:

i need this one too

Explanation:

4 0
3 years ago
. Convert your age into binary and then to hexadecimal. Show your work.
Dovator [93]

Explanation:

Age = 23.

To convert a base 10 number to hexadecimal number we have to repeatedly divide the decimal number by 16 until  it becomes zero and store the remainder in the reverse direction of obtaining them.

23/16=1 remainder = 5

1/16=0 remainder = 1

Now writing the remainders in reverse direction that is 15.

My age in hexadecimal number is (15)₁₆.

5 0
4 years ago
Other questions:
  • You can increase your efficiency by using your e-mail program's spell checker because it eliminates the need for you to proofrea
    11·1 answer
  • If you could make any blog, what would it be about and why?
    9·1 answer
  • Which VMware product would allow administrators, to manage enterprise desktops with increased reliability, security, end-user ha
    11·1 answer
  • How many channels are in an ISDN PRI connection?
    12·2 answers
  • After you enter the details for the first selected recipient in the New Address List dialog box, click _______ to add another re
    9·1 answer
  • Write the definition of a function named printstarbucks that receives a non-negative integer n and prints a line consisting of n
    6·1 answer
  • Computer-generated random numbers are normally distributed. true or false
    11·1 answer
  • This is the number of items arranged in an order.
    7·2 answers
  • Which items in the list below are viruses. Click in the box to select your answer(s).
    8·1 answer
  • Which programming language in order takes the most lines code​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!