Java初学者';s指南,第5版

Java初学者';s指南,第5版,java,Java,我有一个来自Java的例子,一个初学者指南,第5版,但是当我运行它时会出现一些错误。我怎样才能改变它,使它工作 public class ForTest { public static void main(String[] args) throws java.io.IOException { int i; System.out.println("press s to stop"); if(i = 0; (char) System.in

我有一个来自Java的例子,一个初学者指南,第5版,但是当我运行它时会出现一些错误。我怎样才能改变它,使它工作

public class ForTest {

    public static void main(String[] args)  throws java.io.IOException {
        int i;
        System.out.println("press s to stop");

        if(i = 0; (char) System.in.read() != 's'; i++)
            System.out.println("pass # " + i);
    }
}

您可能希望(…)使用
,而不是
如果(…)
。所以请更改

if(i = 0; (char) System.in.read() != 's'; i++)


从读取错误消息开始。如果这段代码真的出现在一本书的第五版中,我想知道第四版到底有多糟糕。是的。。。正在阅读错误消息并将其发布到此处,@Sempliciotto.抱歉,这是一个不适用于if的示例。
for(i = 0; (char) System.in.read() != 's'; i++)
for(i = 0; (char) System.in.read() != 's'; i++)
        System.out.println("pass # " + i);