+ 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
13 ответов
+ 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.
+ 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.
+ 1
Thanks It's fixed!
0
I recommend a solution with switch statement. This is much better structured and more suitable for these cases.
0
I dont wanna recode so suggest me the error Ja Play
0
Ayush Pandey You must replace also 10 with ten.
As for the exception 🤷♂️
0
Bro u use the link in my code to the code coach and try that there
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 🙃
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
0
andriy kan how can that exception be fixed ?
- 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.
- 2
Ayush Pandey Instead of arguing, have you tried replacing 10 also, as per description and my first answer.
- 2
Add try catch for your exception and make that meaningful