I have a class Test with a static method to take input.
class Test {
public static Student readStudent() throws IOException {
Scanner s = new Scanner(System.in);
System.out.println("Enter first name of student");
String fname = s.nextLine();
System.out.println("Enter middle name of student");
String mname = s.nextLine();
System.out.println("Enter last name of student");
String lname = s.nextLine();
System.out.println("Enter name format(1 for ',' and 2 for ';') ");
int num = s.nextInt();
System.out.println("Enter age of student");
int age = s.nextInt();
s.close();
return new Student(new Name(String.join((num == 1) ? "," : ";", fname,
mname, lname)), age);
}
}
I am able to take the input for one student but once i put it in a for loop i get a java.util.NoSuchElementException: No line found
error.
This is my loop
for (int i = 0; i < 10; i++) {
Student s = Test.readStudent();
}
Why am I getting this error? Thanks.