
reads sentence and find the average length of word in it.

Hi Friend,
Try the following code:
import java.util.*;
class AverageLengthOfWords
{
public static void main(String[] args)
{
int sum=0;
Scanner input=new Scanner(System.in);
System.out.print("Enter sentence: ");
String st=input.nextLine();
String str[]=st.split(" ");
int len[]=new int[str.length];
for(int i=0;i<str.length;i++){
len[i]=str[i].length();
}
for(int i=0;i<len.length;i++){
sum+=len[i];
}
int l=len.length;
System.out.println("Avergae Length= "+(sum/l));
}
}
Thanks

thanku
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.