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
Que implicaciones sociales puede tener la robótica
wolverine [178]
Según estos estudios, el impacto de los robots en la productividad ya se compara con la contribución de las máquinas de vapor en el pasado. ... Algunos de los aumentos en la productividad que se derivan de la densificación de los robots se comparten con los trabajadores mediante el pago de salarios más altos.
8 0
3 years ago
How many bits must be "flipped" (i.e., changed from 0 to 1 or from 1 to 0) in order to capitalize a lowercase that’s represented
Alexxandr [17]
Only one ... the third bit of the byte, numerical 32.  Every lower-case letter 
has a '1' in that place.  If that bit is changed to '0', then the code represents
the upper-case form of the same letter.
8 0
3 years ago
Read 2 more answers
What is a router?
uranmaximum [27]

Answer:

A router receives and sends data on computer networks. Routers are sometimes confused with network hubs, modems, or network switches. However, routers can combine the functions of these components, and connect with these devices, to improve Internet access or help create business networks.

I believe the answer would be B). A device that sends data to the receiving device

Explanation:

3 0
3 years ago
By default, only the ________ options are allowed when the worksheet is protected.
Natalka [10]
Im trying to figure tht out to

5 0
3 years ago
Would this program compile run? If not, why; if yes: what would be the output? public class ConstChaini { public static void mai
nikdorinn [45]

Answer:

Check the explanation

Explanation:

// Code to copy

public class ConstChain1 {

public static void main(String[] args)

{

new SubClass();

System.out.println();

new SubClass(1);

}

}

class SuperClass{

public SuperClass() {

System.out.println("D");

}

public SuperClass(int i) {

System.out.println("C");

}

}

class SubClass extends SuperClass{

public SubClass() {

this(10);

System.out.println("B");

}

public SubClass(int i) {

super(i);

System.out.println("A");

}

}

Explanation:

Now each time when a object of a subclass is been created it's super class constructor will be executed first then only subclass object is created by executing it's constructor.

8 0
3 years ago
Other questions:
  • There are two algorithms called Alg1 and Alg2 for a problem of size n. Alg1 runs in n2 microseconds and Alg2 runs in 100n log n
    13·1 answer
  • What is an administrator?
    15·1 answer
  • What makes a distributed denial of service attack "distributed"? It involves many ip addresses. It attacks multiple systems. It
    9·1 answer
  • Which of the following operating systems is able to join a domain a) Microsoft office pro b) Microsoft surface R.T. c) google an
    9·2 answers
  • HELP 99PTS If Answered
    12·2 answers
  • Suppose we want an error correcting code that will allow all single-bit errors to be corrected for memory words of length 15. 1.
    5·1 answer
  • Which of the following is not the disadvantage of closed
    7·2 answers
  • You already know how to use lists. What is the index of 5 in the following list?
    9·1 answer
  • How do I type fast?<br><br> Give me an actual answer...
    11·2 answers
  • (40 PTS) Be specific
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!