+ 1
Why this is not working?[Java]
This code ain't running, idk why. Please help. Its aim is to take the marks of maths, English, science for a given number of students and display each of their total and average and also the class's average. https://code.sololearn.com/cWcDT202oWMZ/?ref=app
2 Answers
+ 4
It is a very common problem while taking input in Java. It's explained in this article
https://www.geeksforgeeks.org/why-is-scanner-skipping-nextline-after-use-of-other-next-functions/
As you'll see in the article, the solution is to do a blank `sc.nextLine();` after a sc.nextInt() and before another sc.nextLine(). So to fix your code, simply add a line
`sc.nextLine();`
as the first statement of the while loop
0
XXX Thank you very much. I was actually aware of this concept but I never had to face it in a loop. Thank you!



