+ 1
i want to find average word length in sentence. whats wrong here?
6 Answers
0
Line 10- remove () because it is only used to get string length but you are getting the length of an array so it should be-
int e=d.length;
+ 4
Harithra Shanmugam Nothing wrong there just Share your code so we can check.
+ 3
Harithra Shanmugam
Change split("\\s+") to split(" ")
Change d.length() to d.length
Change replaceAll(" ", "") to replaceAll("\\s", "");
Change System.out.println(f) to System.out.println(Math.round(Math.ceil(f)))
and also you should count only alphabets (a.length() will count all the character)
+ 1
AJ #Infinity Love it shows lossy conversion of long to int
+ 1
Convert the input into a char array and inspect for letters (shown in posted code. Note: The Math. ceil func and int conversion were for a specific need), or use regex to yank out invalid chars.
https://code.sololearn.com/cRE8rRS8Huue/?ref=app