【发布时间】:2020-10-19 17:07:21
【问题描述】:
我创建了一个嵌套的 while 循环,如 image 所示,但是,在第一个完整循环完成后,即使第二个 while 循环内的条件仍然为真,第二个 while 循环也不会执行。这可能是System.in 的问题,但我尝试将其注释掉,但它仍然没有再次循环。这可能是什么问题?
int i = 0;
int j = 0;
int p = 0;
while(i < nStudents) {
p = i+1;
System.out.println("\nStudent " + p + "'s rankings: ");
while(j < nSchools) {
System.out.print("\nSchool " + toArrayList.get(j).getName() + ": ");
String ranking = DisplayMenu.br.readLine();
Array1.add(ranking);
j++;
}
i++;
}
我还包含了一个image,它显示了这里到底发生了什么。第二次循环,它应该打印出学校,但它没有。
【问题讨论】:
-
这只是显示两个 while 循环及其打印内容的源代码。我将编辑问题以显示代码。
-
@PartialDifferentials 请务必提供可编译代码!!!
-
@oleg.cherednik 我会添加它,但它的 5 个源文件...
-
请了解minimal reproducible example的概念。
标签: java while-loop bufferedreader