0
import java.util.Scanner;

public class FractionTester
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int num2 = scan.nextInt();
        int num3 = scan.nextInt();
        int num4 = scan.nextInt();
    }
}

This code keeps throwing the error FractionTester.java: Line 10: java.util.NoSuchElementException can anybody explain why or how to fix it, please? Thank you all in advance.

2020bz
  • 1
  • Does this answer your question? [Java scanner input loop throwing No Such Element exception after first loop](https://stackoverflow.com/questions/67843207/java-scanner-input-loop-throwing-no-such-element-exception-after-first-loop) – FairOPShotgun Jun 08 '21 at 00:19

1 Answers1

0

are you sure you are passing 4 input values to the prompt because as its name says NoSuchElementException means scan.nextInt() is not getting any element. I had tried you code in local and its working for me while passing 4 input values. see the below code I am giving 4 values to it

enter image description here

now in here see I am giving only 3 values so it throw the exception enter image description here

Gopal Oswal
  • 154
  • 1
  • 3
  • Ok thank you for your help with the explanation this is what I was thinking but didn't know how to test it for my self have a great day. – 2020bz Jun 07 '21 at 17:29
  • if you are using CLI then go like this javac filename.java then run java FractionTester and in the console type your values – Gopal Oswal Jun 08 '21 at 05:23