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

How did President Theodore Roosevelt's Big Stick policy differ from Dollar Diplomacy and Moral Diplomacy
Read this passage from “A Worn Path.” What can the reader infer about Phoenix from this passage? In the paved city it was Christmas time. There were red and g
Determine whether the three segment lengths will produce a triangle. Type yes or no in the space provided. 20, 20, 30 = ?
a person who helps mange relation between countries is known as ____​
AL(OH)2 is__ an acid a base a salt
20 pen cost $1.60 what is the unit rate
If U VYX is a parallelogram what is the value of Y
Based on evidence in the passage, what inference canbe made about Della?​
IDK what a monalog is You will write your own monologue. View the grading rubric as you complete your assignment. This is your guide to a super submission. In y
Can anyone help me? Factorise: 81m^2-1