Java code mistake | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Java code mistake

Can anyone please😔 tell me what mistake have i done here in my program Average word finder , from code coach. import java.util.Scanner ; public class Program { public static void main(String[] args) { Scanner ab = new Scanner(System.in); String para = ab.nextLine(); int n=0; String p[]= para.split(" "); int t= p.length; for(int i=0; i< t ; i++) { for(int j=0 ; j< p[i].length(); j++) { if(Character.isLetter(p[i].charAt(j))) { n=n+1; } }} int k= (int)Math.ceil(n/t); System.out.println(k); } } https://code.sololearn.com/c75X6qu6FOvF/?ref=app Plz friend find whats the bug here in this program when i did put this code in test run , accept the first case all cases were wrong😞.

29th Mar 2021, 7:58 AM
Abhishek Pandey
Abhishek Pandey - avatar
5 ответов
+ 3
n/t is an int divided by an int which will result in integer division, truncating any fractional part. So, no rounding will actually take place. int k= (int)Math.ceil((float)n/t);
29th Mar 2021, 8:14 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Did you see the code change I provided in my last post? You just need to convert one or both of the numbers in the division to a float so that it will result in a float. If you still aren't passing all the test cases after that change, then there is an additional issue.
29th Mar 2021, 8:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Wow bro thanx very much it really worked , n sorry mine mistake i didn't saw😀
29th Mar 2021, 8:51 AM
Abhishek Pandey
Abhishek Pandey - avatar
0
Hmm so it seems that i dont need Math.ceil option I should rather write K= n/t; Sop(k); ?? Say bro?
29th Mar 2021, 8:23 AM
Abhishek Pandey
Abhishek Pandey - avatar
0
But bro that doesn't works either what should i do plz suggest
29th Mar 2021, 8:25 AM
Abhishek Pandey
Abhishek Pandey - avatar