I am working on some basic java skills are I am getting a NoSuchElementExemption when I am debugging. My goal is to ask two questions in two different methods and combine them in the main function. Could someone explain the rule that I am breaking?
The code is as follows:
import java.util.Scanner;
public class TwoInputs{
public static double test()
{
Scanner reader2 = new Scanner(System.in);
System.out.println("Enter a number ");
double n2 = reader2.nextDouble();
if (n2 %1 != 0) {
System.out.println("Number is invalid");
} else {
reader2.close();
System.out.println("You put the number " + n2);
}
return n2;
}
public static double test2()
{
Scanner reader1 = new Scanner(System.in);
System.out.println("Enter a number ");
double n1 = reader1.nextInt();
if (n1 %1 != 0) {
System.out.println("Number is invalid");
} else {
reader1.close();
System.out.println("You put the number " + n1);
}
return n1;
}
public static void main(String[] args) {
double sum = test();
double sum2 = test2();
System.out.println("You put the number " + sum+ "and"+ sum2);
}
}