Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error while taking input from the user. NoSuchElementException

import java.util.Scanner;
public class Main {
public static void main(String [] args) {
Scanner sc=new Scanner (System.in);
System.out.println("Enter any two numbers: ");
int a,b,c;
a=sc.nextInt();
b=sc.nextInt();
c=a+b;
System.out.println("The sum = "+c);
}
}

enter image description here

I did the same program on VS Code – it ran without issue.

I used the following online IDEs:-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. tutorialspoint.com (same error)
  2. jdoodle.com (executed successfully)
  3. onlinegdb.com (executed successfully)
  4. programquiz.com (executed successfully)
  5. online-java.com (executed successfully)
  6. w3schools.com (same error)
  7. interviewbit.com (same error)

I had to use an online IDE for my interview – I don’t remember.

I have tried to understand the exception, but I cannot align my issue with what the exception is all about. I’ve read multiple stack overflow threads about this issue. Some people are saying, I should not use close() – but I haven’t even used it! Others are giving solutions that are not related to my issue at all.

Please give me some directions or hint so that I can learn from this problem.

>Solution :

I think it is more on how the IDE is written, may be it is not giving you an interactive screen to give an input and expects you to do that separately.

Just checked this for w3schools.com and interviewbit.com where we have a separate section for giving the input and this code runs perfectly fine there.

See both the screen shots attached
input tab

W3Schools

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading