我试图使循环继续在此处执行,直到用户在键盘上键入字母S为止。似乎每次迭代给出三个输出,而不是一个。我在这儿做错了什么?
// Loop until an S is typed
public class ForTest {
public static void main(String[] args)
throws java.io.IOException {
int i;
System.out.println("Type S to stop.");
for(i = 0; (char) System.in.read() != 'S'; i++)
// System.out.println("print");
System.out.println("Pass # " + i);
// System.out.println("print");
}
}
输出结果是如果我按“ a”:
Type S to stop.
a
Pass # 0
Pass # 1
Pass # 2
相关分类