Error NoSuchElementException

Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:85).

Help me with this error! What’s the mistake in my code?
I’m trying to build a generic tree and get the sum for kth level. It’s working fine on other editors but not on this!

Hey @mittalpranjal12,
Please share your code using cb.lk/ide so that I can go through your logic.

https://ide.codingblocks.com/ I hope u r able to see my code

Hey @mittalpranjal12,
I went through your code, and the logic was completely correct.
The only suggestion I can make is that instead of declaring new Scanner everytime, you can make a static scanner for the entire Java class:
Here’s your updated code : https://ide.codingblocks.com/s/598737
I hope it helps :slight_smile:
Please mark the doubt as resolved if I have cleared your doubt.

Thank You for your hep!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.