drfrosc000 drfrosc000
  • 14-09-2021
  • Computers and Technology
contestada

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

Respuesta :

maythiabbj maythiabbj
  • 14-09-2021

Answer:

import java.util.*;

class StringProgram

{

public static void main(String s[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter a Sentence: ");

String str= sc. nextInt();

// trim the white spaces at the beginning and at the end.

str = str.trim();

int c=0;

int i=0;

while(str.charAt(i++)!=' ')

++c;

System.out.println("Length of the first word in the sentence is: "+c);

}

}

Explanation:

Answer Link

Otras preguntas

A person given palliative care is probably:
the number sentence is an example of which multiplication property 6×7=(6×5)+(6×2)
Which of the following acts best show how powerful is Shi huangdi was-burning books, forcing nobles to move, or forcing commoners to work on goverment
The ____________ of the Supreme Court presides over oral arguments, influences the direction of discussions, and decides which cases the Court will hear.
Consider the inequality -5(x 7) -10. Write an inequality representing the solution for x.
In a controlled experiment, which group experiences the test?
Plz really ned help on this really easy!! simplify: 4(5x + 12) Thank you all in advance!!!
Of the following statements, which does not describe a key feature of consciousness? a. Consciousness is continuous. b. Consciousness is selective. c. Consci
Giving space and respecting privacy are two ways to build a healthy family relationship. T F
#4 and 5. can u tell me anything about it