I'm trying to let the user enter a specific amount of entries. First the user would be asked the following question:
Enter amount of students:
and he would enter a integer, now the code should ask the following questions:
Please enter name of student 0:
After he entered the name it should ask the next question such as:
Please enter score of the following student: name:
And he should enter the score. After this the loop should restart as often as in the first question answered.
Sadly the program would instantly ask the following questions:
Please enter name of student 0:
Please enter score of the following student: :
and throw a error after I entered something as you see in this screenshot:
Does anyone know why? Here's my code:
package code;
import java.util.*;
public class MainCode {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter amount of students: ");
int studentsAmount = input.nextInt();
int loopRuns = 0;
do{
System.out.println("Please enter name of student " + loopRuns + ": ");
String firstName = input.nextLine();
System.out.println("Please enter score of the following student: " + firstName + ": ");
int score = input.nextInt();
// Do stuff with the firstname and amount
loopRuns++;
}while(loopRuns <= studentsAmount);
}
}