+ 1

i want to find average word length in sentence. whats wrong here?

https://www.sololearn.com/coach/73?ref=app

13th May 2020, 10:03 AM
Harithra Shanmugam
6 odpowiedzi
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;
13th May 2020, 10:26 AM
Avinesh
Avinesh - avatar
+ 4
Harithra Shanmugam Nothing wrong there just Share your code so we can check.
13th May 2020, 10:08 AM
A͢J
A͢J - avatar
+ 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)
13th May 2020, 10:31 AM
A͢J
A͢J - avatar
13th May 2020, 10:12 AM
Harithra Shanmugam
+ 1
AJ #Infinity Love it shows lossy conversion of long to int
13th May 2020, 10:41 AM
Harithra Shanmugam
+ 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
13th May 2020, 11:01 PM
Adam Douglas
Adam Douglas - avatar