+ 1

Please help fixing this out!

There is a challenge in code coach which I tried solving I am getting all the test correct except one that is hidden Also when I try it in codeplayground normally it gives output but there is also an NoSuchElementException So plz can u tell m why there is the exception and also what I am missing in my code that one test is resulting wrong plz help in fixing https://code.sololearn.com/cEqjnIET623f/?ref=app

29th Feb 2020, 10:38 AM
Ayush Pandey
Ayush Pandey - avatar
13 odpowiedzi
+ 2
NoSuchElementException arises because you don't check the availability of data in the Scanner before reading it. change line#27 to while(sc.hasNext()) also your code doesn't replace 10 to "ten", appen it.
29th Feb 2020, 12:15 PM
andriy kan
andriy kan - avatar
+ 1
Error was occur in line no 29 becz you take input from user inside while loop and that loop run infnite, However your programm still incorrect.
29th Feb 2020, 11:53 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
Thanks It's fixed!
29th Feb 2020, 12:51 PM
Ayush Pandey
Ayush Pandey - avatar
0
I recommend a solution with switch statement. This is much better structured and more suitable for these cases.
29th Feb 2020, 11:31 AM
JaScript
JaScript - avatar
0
I dont wanna recode so suggest me the error Ja Play
29th Feb 2020, 11:33 AM
Ayush Pandey
Ayush Pandey - avatar
0
Ayush Pandey You must replace also 10 with ten. As for the exception 🤷‍♂️
29th Feb 2020, 11:41 AM
Mihai Apostol
Mihai Apostol - avatar
0
Bro u use the link in my code to the code coach and try that there
29th Feb 2020, 11:55 AM
Ayush Pandey
Ayush Pandey - avatar
0
This way you can better see what you have done and fix your solution by yourself. And this is much more valuable for a learning process 🙃
29th Feb 2020, 11:55 AM
JaScript
JaScript - avatar
0
I have tried there. I m not one who likes spoon feeding...u better try what I suggested u then u reply me of ur observation
29th Feb 2020, 11:58 AM
Ayush Pandey
Ayush Pandey - avatar
0
andriy kan how can that exception be fixed ?
29th Feb 2020, 12:47 PM
Ayush Pandey
Ayush Pandey - avatar
- 1
@Ayush Pandey To fix that exception you should replace true in line #27 with sc.hasNext() See my previous post, I wrote about it.
29th Feb 2020, 12:50 PM
andriy kan
andriy kan - avatar
- 2
Ayush Pandey Instead of arguing, have you tried replacing 10 also, as per description and my first answer.
29th Feb 2020, 12:05 PM
Mihai Apostol
Mihai Apostol - avatar
- 2
Add try catch for your exception and make that meaningful
29th Feb 2020, 6:05 PM
tauseef ansari
tauseef ansari - avatar