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
Ainat [17]
2 years ago
6

Write code which takes a sentence as an input from the user and then prints the length of the first word in that sentence.

Computers and Technology
1 answer:
Afina-wow [57]2 years ago
7 0

import java.util.Scanner;

public class U2_L3_Activity_Four {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a sentence.");

       String sent = scan.nextLine();

       int count = 0;

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

           char c = sent.charAt(i);

           if (c != ' '){

               count++;

       }

           else{

               break;

           }

       

   }

       System.out.println("The first word is " + count +" letters long");

   

   }

}

We check to see when the first space occurs in our string and we add one to our count variable for every letter before that. I hope this helps!

You might be interested in
You want to divide the value in cell D3 by the value in cell E3. Which formula should you use?
Tom [10]
The formula is:
=D3/E3
4 0
3 years ago
Read 2 more answers
If a user wished to insert a triangle or a callout figure in a document, he or she should select the _____ option.
Vlada [557]
The Insert Tab option

You can add a shape your word, excel or PowerPoint document to make a drawing. To do this in MS Word, click on the Insert tab, and in the illustration group, click on the shapes option. Click the shapes or callouts that you would like to insert and then drag to place the shape anywhere in the document.






4 0
2 years ago
If a firm is set to use open-source software with which no one in the IT department is familiar, what should it do? fire the IT
Aleonysh [2.5K]
The most efficient thing to do would be to provide training as firing or doing nothing halts productivity indefinitely while training eventually will finish
7 0
2 years ago
Read 2 more answers
The difference between the centerline of a vehicle and the line perpendicular to the rear wheels is called what?
snow_lady [41]
The thrust angle is an imaginary line drawn perpendicular to the rear axle's centerline. It compares the direction that the rear axle is aimed with the centerline of the vehicle. It also confirms if the rear axle is parallel to its front axle and that the wheelbase on both sides of the vehicle is the same.
7 0
3 years ago
How can you insert an image file in your word document?​
Margarita [4]

Click the insert tab, it'll show a pop up window. Go to the location of where your picture may be. Double click on the photo, and it will be inserted into the word document.

6 0
2 years ago
Other questions:
  • You should use html elements instead of server controls when
    11·1 answer
  • Computer user support helps people with minor computer problems. <br><br> True or False
    12·1 answer
  • How to get out of compatibility mode in word?
    15·1 answer
  • Explain the importance of determinism in an industrial LAN
    8·1 answer
  • How was the Big Ben project similar to the investigation you conducted in class to determine if the table was vibrating? How is
    7·1 answer
  • One student will be stationed near you in a coffee shop. The other student will be located two miles away from your school. You
    10·2 answers
  • WILL GIVE BRAINLIEST! 20 POINTS! PLZ HELP!
    14·2 answers
  • . Imagine that you were programming without an IDE. What problems might you encounter?​
    12·1 answer
  • Using a wireless technology known as ___, many smartphones can now be tapped on special payment devices to complete your purchas
    13·1 answer
  • Which one did I buy the iPhone 13 or the Samsung S22 Ultra?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!