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]
3 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]3 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
Which statement below is true about how the functions of the digestive and circulatory system are connected.
telo118 [61]

Answer:

The digestive system breaks down the food into molecules that can be used by the cells. The circulatory system moves the molecules from the villi to all cells in the body.

8 0
3 years ago
What would be a reason for using a workstation rather than a personal computer?
Pavlova-9 [17]
You can easily organize your work space. also you may have more resources. hope this helps
4 0
3 years ago
Camera lenses typically have very long focal points. true or false.
Alisiya [41]
No, it is false. This is mainly because there would be no need.
8 0
3 years ago
Read 2 more answers
Trading stock or selling stock, selling real estate for profit, and selling other assets that gain value over time.
Andrei [34K]

Answer:

D is reasonable

Explanation:

3 0
2 years ago
0 Select the correct answer. Which is an advantage of programming with a procedural language? A. Procedural program code is easy
Novosadov [1.4K]

Answer:

D. Algorithms of simple problems are readily available for reference. ​

Explanation:

Hope this helps you! Ask me anything if you have any quistions!

7 0
3 years ago
Other questions:
  • Cliff just started working with a client who has a very disorganized AdWords account. What’s an effective way for him to begin r
    15·1 answer
  • If a table is designed so that every determinant is a candidate key, then that relation is in ________.
    14·1 answer
  • Why laptop computer is called micro computer?​
    8·1 answer
  • For which type of long-distance call do you need to tell the operator the name of the person to whom you wish to speak?
    10·1 answer
  • I need urgent help. which of these network has minimum data loss. a. LAN b. MAN c. WAN ​
    11·1 answer
  • Ethical design refers to...
    13·1 answer
  • How can injection attacks be prevented? Check all that apply
    6·2 answers
  • Hoda is creating a report in Access using the Report Wizard. Which option is not available for adding fields using the wizard?
    15·2 answers
  • Each instruction that the CPU receives contains two parts -
    12·1 answer
  • HELP ME ⚠️‼️⚠️‼️ DUE IN EXACTLY 27 MINUTES
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!