[英]Why does my program print the same line “Student #” twice?
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();
For the most part, my program is running as expected, up until it starts repeating the last output twice.在大多数情况下,我的程序按预期运行,直到它开始重复最后一次 output 两次。 Why is it doing that and how can I stop it?
为什么要这样做,我该如何阻止它?
It should do the trick:它应该可以解决问题:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.