【发布时间】:2019-03-12 15:38:23
【问题描述】:
我是社区的新人,我需要 Java 中的 Array 2d 方面的帮助 是学校的项目 这是我的问题
我用静态长度构建 Array 2D 并且可以工作,但是带有参数的相同代码不起作用。
首先打印 System.out.print("Insert Name");
之后不执行语句matrix[i][0] = input.nextLine();
第三次打印 System.out.print("插入姓氏");
现在可以工作,但索引 [0],[0] 为空
打印示例:
一个
b b
c c
谢谢!!!
import java.util.*;
public class Students {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Insert number of Students");
int numStudents = input.nextInt();
String[][] matrix = new String[numStudents][2];
for (int i = 0; i < numStudents; i++) {
System.out.print("Insert Name");
matrix[i][0] = input.nextLine();
for (int j = 1; j < 2; j++) {
System.out.print("Insert Last Name");
matrix[i][j] = input.nextLine();
}
}
for(int z=0; z<numStudents ;z++) {
System.out.println();
for(int h=0; h<2;h++) {
System.out.printf(matrix[z][h]);
System.out.printf(" ");
}
}
}
}
【问题讨论】:
-
重复stackoverflow.com/questions/13102045/… 在
input.nextInt()之后添加input.nextLine()
标签: java arrays eclipse parameters 2d