为了账号安全,请及时绑定邮箱和手机立即绑定

Java For循环中的逻辑错误

Java For循环中的逻辑错误

米脂 2021-05-01 15:12:33
我试图使循环继续在此处执行,直到用户在键盘上键入字母S为止。似乎每次迭代给出三个输出,而不是一个。我在这儿做错了什么?// Loop until an S is typedpublic 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.aPass # 0Pass # 1Pass # 2
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 151 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信