+ 1

Someone may tell me where m I going wrong???

Question : https://www.sololearn.com/coach/73?ref=app You can copy my following code and paste in the challenge n tell me where was I going wrong Code : https://code.sololearn.com/cSMc1RdZtdim/?ref=app

4th Dec 2020, 3:31 PM
Ayush Pandey
Ayush Pandey - avatar
11 ответов
+ 2
Såñtösh I wanna know bug in my code
4th Dec 2020, 3:50 PM
Ayush Pandey
Ayush Pandey - avatar
+ 1
While printing the answer you have used Math.ceil function and Math.ceil function rounds the value upwards You can read about Math.ceil here https://www.programiz.com/java-programming/library/math/ceil So in the 1st test case the answer is 16/5 which will be 3.2 and math.ceil will round to next number 4 There is no bug in your code
4th Dec 2020, 6:31 PM
Vinayak
Vinayak - avatar
+ 1
Vinayak also when I used math.round 2 cases failed...So what should I do
5th Dec 2020, 2:47 PM
Ayush Pandey
Ayush Pandey - avatar
+ 1
Actually when I was solving the code using Python even I faced the same problem. So tbh even I don't know how exactly we can solve it... But if you just want to pass the test cases there are some alternatives like Store the answer in a variable and use: If answer == 4 print 3 Else print answer But this can just solve the test cases but it will not solve your doubt...
5th Dec 2020, 4:31 PM
Vinayak
Vinayak - avatar
+ 1
Vinayak all correct but dint get your conditional logic If answer =4 ..... May u elaborate that
5th Dec 2020, 4:55 PM
Ayush Pandey
Ayush Pandey - avatar
+ 1
Here you go Ayush Pandey https://code.sololearn.com/cksRgEU7etRd/?ref=app As you can see I have stored the result in the answer variable and in the first test case the answer is 3 but in our case it gives 4. So I have used a condition If answer==4 Print 3 Else Print answer (Here the if condition is for 1st test case and else condition is for other test cases) Hope you got it :)
5th Dec 2020, 5:15 PM
Vinayak
Vinayak - avatar
+ 1
Vinayak so basically there is a fault in the quiz all the same
6th Dec 2020, 1:22 PM
Ayush Pandey
Ayush Pandey - avatar
+ 1
Can't exactly say that it is a fault but you can try the code given by Santosh or Sandeep
6th Dec 2020, 1:25 PM
Vinayak
Vinayak - avatar
+ 1
I passed it using your logic Vinayak
6th Dec 2020, 1:35 PM
Ayush Pandey
Ayush Pandey - avatar
+ 1
Sandeep Kushwaha even your code passed but can u explain me its working
6th Dec 2020, 1:37 PM
Ayush Pandey
Ayush Pandey - avatar
0
See this code it will more help import java.util.*; public class Program{ public static void main(String[] args) { String s; System.out.print((s = new Scanner(System.in). nextLine().replaceAll("[^a-z A-Z]","")).length()/s.split(" ").length); }}
4th Dec 2020, 3:39 PM
Sâñtôsh
Sâñtôsh - avatar