I want to fill a multidimensional array using user input inside a loop but it skips the first input and proceeds to the next. Here is my code
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("number of batches: ");
int a = input.nextInt();
System.out.print("number of students: ");
int b = input.nextInt();
String[][] list = new String[a][b];
String name;
for (int j = 0; j < a; j++) {
for (int i = 0; i < b; i++) {
System.out.print("enter a student: ");
list[j][i] = input.nextLine();
}
}
}
}
here is the result:
number of batches: 2
number of students: 3
enter a student: enter a student:
//the first input was skipped