简体   繁体   English

为什么我的打印语句在一段时间循环后没有产生 output?

[英]Why is my print statement producing no output after a while loop?

What's wrong with this version of this code?这个版本的代码有什么问题? (I read something about an "incorrect exit condition" but I don't see how that could be?) (我读到了一些关于“不正确的退出条件”的文章,但我不明白这是怎么回事?)

import java.util.*;

public class First {

    public static void main(String[] args) {

        ArrayList<String> lineOne = new ArrayList<String>();

        Scanner scan = new Scanner(System.in);

        while(scan.hasNext()){
              String lineOneVar = scan.next();
              lineOne.add(lineOneVar);
              /*System.out.println(lineOneVar);
              System.out.println(lineOne);
              System.out.println(lineOne.get(0));*/
        }

        System.out.println(lineOne);
        //Does not produce an output.
    }
}

You should use the below concept您应该使用以下概念

if(s1.equals("exit")) {
        break;
}

Please see this solution 请看这个解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM