数组的第一个元素是al;方法null - java

时间:2015-06-05 18:51:36

标签: java

每当我把第一个学生的名字放在显示它们的时候,它总是显示为空,但是没有别的。这是什么?

package school.register;
import java.util.Scanner;

public class SchoolRegister {
    public static void main(String[] args) {
        Scanner Input = new Scanner(System.in);
        String[][] Students = new String[5][2];
        int i = 0;
        int j = 0;
        for (i = 0; i < 5; i++) {
            System.out.println("Please put in a students name.");
            Students[i][j] = Input.nextLine();
            for (j = 0; j < 1; j++) {
                System.out.println("Please put in a students test score.");
                Students[i][j] = Input.nextLine();
            }
        }
        System.out.println("Score\tName");
        display(Students);

    }

    public static void display(String x[][]) {
        for (int row = 0; row < x.length; row++) {
            for (int column = 0; column < x[row].length; column++) {
                System.out.println(x[row][column]);

            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

试试这个:

public static void main(String[] args) {
        Scanner Input = new Scanner(System.in);
        String[][] Students = new String[5][2];
        int i;
        int l = 0;
        for (i = 0; i < 5; i++) {

            System.out.println("Please put in a students name.");
            Students[i][0] = Input.nextLine();
            System.out.println("Please put in a students test score.");
            Students[i][1] = Input.nextLine();
        }
        System.out.println("Score\tName");
        Display(Students);

    }

答案 1 :(得分:0)

System.out.println("Please put in a students name.");
Students[i][0] = Input.nextLine();
System.out.println("Please put in a students test score.");
Students[i][1] = Input.nextLine();