猿问

Java For循环中的逻辑错误

我试图使循环继续在此处执行,直到用户在键盘上键入字母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


米脂
浏览 152回答 3
3回答
随时随地看视频慕课网APP

相关分类

Java
我要回答