Computer Science, asked by rupasanfui47, 10 months ago

write a program in java to input a sentence and find and display the number of words present in the sentence and the number of letters present in the sentence. please write the whole program​

Answers

Answered by rambabutm80
2

Answer:

i dont know java brother only c . c++. python. oracle.hmtl

Explanation:

brainlist bro

Answered by saloni766
3

Answer:

In JAVA

import java.util.Scanner;

public class ToCountNumberOfWords{

public static void main(String[] args)

{

 

 Scanner T=new Scanner(System.in);

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

 

 while(T.hasNext())

 {

   

  String line=T.nextLine();

  /* this string will contain the words that are split or we can say break by the split function

  split function takes parameter i.e from where we have to split the string

  here,that parameter is a space as soon as it will find a space,it will break that into substring from there

  and store them in string array arr with an index  

  */

  String[] arr=line.split(" ");

  //counter to count the number of words initialized to zero

  int word=0;

  //looping to count the number of words in array  

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

{

   word++;

  }  

  //print the number of words in a sentence

  System.out.println(word);

 }

}

}

I hope it will help you..

Similar questions