打破while循环?

时间:2015-06-02 04:09:27

标签: java loops while-loop break

我如何在循环中突破这个?当我输入“完成”时,我希望它能够突破它。但它似乎不起作用。

public class Main {

    public static void main(String[] args) throws IOException {

        PlayerReader r = new PlayerReader();
        PlayerWrite w = new PlayerWrite();
        r.Check();

        System.out.println("Welcome, Please type enter or type finish to store information");

        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();
        String cond = "finish";

        while(str != cond)
        {

            w.writeName();
            w.writeScore();
            if(str == cond)
            {
                System.out.println("Information stored");
                sc.close();
                break;
            }

        }


    }


}

0 个答案:

没有答案