我很难终止java循环

时间:2015-11-21 09:24:27

标签: java loops

我敢肯定,如果您阅读了该片段,您就会理解我正在尝试做的事情。但是,我首先使用null""进行了尝试。我认为.eoln()不起作用,因为我要求输入多行,其中所有行都有一行。我最好在用户返回空行时终止循环。对于更多背景知识,我使用== / !=.equals()运算符/方法进行了实验。我也试过do/while无济于事。

添加星号以测试空字符串是否为while语句的问题。

有人可以解释一下我对Java / TextIO的理解吗?

编辑 - 修订的代码段:

  while(write){
        pl("Begin writing content to fill file.");
        pl("");
        pl("Return a line with a single SPACE or"); 
        pl("\"\\n\" to represent line breaks in your");
        pl("");
        pl("Return two asterisks ** when done writing,");
        pl("and you will be then prompted to select a file");
        pl("to save your writing to.");


        String input = TextIO.getln();;
        String value = new String();
        while(!(input.equals(""))) {
            if (input == " " || input == "\\n") {
                value += "\\n" + "\\n";
            } else {
                value += input + " ";
            } // end if/else //
            input = TextIO.getln();
        } // end while(input) //
        TextIO.writeUserSelectedFile();
        p(value);
        TextIO.writeStandardOutput();
        pl("Would you like to write to another file?");
        Boolean cont = TextIO.getBoolean();
        write = cont;   
     }
  }

0 个答案:

没有答案
相关问题