我想在循环内使用用户输入来填充多维数组,但是它会跳过第一个输入并继续进行下一个输入。这是我的代码
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();
}
}
}
}
结果如下:
number of batches: 2
number of students: 3
enter a student: enter a student:
//第一个输入被跳过