为什么我的程序在同一行“ Student#”上打印两次?

时间:2019-11-09 21:43:52

标签: java

public static void main(String[] args) {
    int[][] coursesRemTak = new int[10][2];
    java.util.Scanner input = new Scanner(System.in);
    System.out.print("Enter classes remaining and taking each term for...\n");
    for (int i = 0; i < coursesRemTak.length; i++) {
        for (int j = 0; j < coursesRemTak[i].length; j++) {
            System.out.printf("Student %d: ", i + 1);
            coursesRemTak[i][j] = input.nextInt();
            if (coursesRemTak.length >= 0 && coursesRemTak[0].length <= 21) {
            }
        }
    }
    input.close();

在大多数情况下,我的程序将按预期运行,直到开始将最后一次输出重复两次。 为什么这样做,我该如何阻止呢?

1 个答案:

答案 0 :(得分:-1)

应该可以解决问题:

public static void main(String[] args) {
    int[][] coursesRemTak = new int[10][2];
    java.util.Scanner input = new Scanner(System.in);
    System.out.print("Enter classes remaining and taking each term for...\n");
    for (int i = 0; i < coursesRemTak.length; i++) {
        System.out.printf("Student %d: ", i + 1);
        for (int j = 0; j < coursesRemTak[i].length; j++) {
            coursesRemTak[i][j] = input.nextInt();
            if (coursesRemTak.length >= 0 && coursesRemTak[0].length <= 21) {
            }
        }
    }
    input.close();