0

Is the expected output of "Average Word Length" of code coach wrong..?

I tried solving that many times but always the output is coming wrong. The explanation of this program shows that its average word length is 5.20 and it has been rounded to 6. Is this possible? I have studied that if the digit in tenths place is more that 5 then only the whole number gets incremented otherwise the smallest integer is retained. So on rounding 5.20 to the nearest integer, we get 5 not 6. And most of the expected outputs are showing wrong.

22nd Jan 2021, 5:56 AM
Hemant Prakash
Hemant Prakash - avatar
3 Answers
+ 2
Please post your CODE here: And don't post repeated questions. Use search bar before asking. https://www.sololearn.com/discuss/1316935/?ref=app
22nd Jan 2021, 6:36 AM
Ezra Bridger 2207 [INACTIVE]
Ezra Bridger 2207 [INACTIVE] - avatar
0
But if you are doing on python here's my code for reference: from math import ceil s=input().split() c=0 d=0 for i in range(len(s)): for j in range(len(s[i])): if(s[i][j]!='?'): c+=1 d+=1 x=c/d print(ceil(x))
22nd Jan 2021, 6:37 AM
Ezra Bridger 2207 [INACTIVE]
Ezra Bridger 2207 [INACTIVE] - avatar
0
Ezra Bridger 2207, I am doing on java and here's the code:- import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String sentence=sc.nextLine(); String array[]=sentence.split(" "); int length=sentence.length(); int length1=array.length; int count=0; for(int i=0;i<length;i++) { char letter=sentence.charAt(i); boolean check=Character.isLetter(letter); if(check) count=count+1; } double a=count/length1; int avg=(int)Math.ceil(a); System.out.println(avg); } }
22nd Jan 2021, 6:42 AM
Hemant Prakash
Hemant Prakash - avatar