虽然数字大小写在布尔值中匹配,但循环不会在java中终止

时间:2016-02-11 18:23:54

标签: java

import java.lang.Math;

public class LogicTableGenerator

{

    public static void main(String[] args)

    {
        double numletters;
        System.out.println("how many letters exist in your logic table?");
        numletters=TextIO.getInt(); double totalpremises;
        totalpremises=Math.pow(2.0,numletters);
        System.out.println("what letters are you using?");
        char letter; letter = 'A'; char letter1, letter2, letter3, letter4,letter5,letter6,letter7,letter8,letter9;
        int numstop; numstop =0;
        System.out.println(numstop);
        boolean bag;
        bag=(1!=1);
        System.out.println(bag);

        while (!(numstop == 1))
        {
            letter1=TextIO.getChar();
            System.out.println("Do you awant to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            System.out.println(numstop);
            letter2=TextIO.getChar();
            System.out.println(numstop);
            System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            letter3=TextIO.getChar();
            System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            letter4=TextIO.getChar();
            System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            letter5=TextIO.getChar();
            System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            letter6=TextIO.getChar();
            System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            letter7=TextIO.getChar();
            System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            letter8=TextIO.getChar();
            System.out.println("Do you want to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            letter9=TextIO.getChar();
            System.out.println("You have reached the end of the road. You are now done.");

        }


    }

}

我不明白为什么这不停止,一旦numstop等于1不应该循环终止?

堆栈溢出让我发布更多详细信息,并且确实没有任何内容可以发布请不要阅读本文,因为它只包含一堆字,如果你还在阅读请立即停止阅读

3 个答案:

答案 0 :(得分:1)

循环将继续循环结束,此时它将检查while循环是否仍然有效。从本质上讲,它将执行while循环内的所有内容,无论如何,并且不会停止重新考虑while循环条件是否仍然有效,直到它到达结束,然后循环回来。

答案 1 :(得分:1)

目前还不清楚你的代码的目的是什么,但如果你想打破那些展开的东西,你需要检查导致循环在每个数字输入后退出的情况,然后手动破解循环。虽然我很困惑为什么你不会将每个字符附加到字符串而是然后循环直到遇到停止令牌然后手动中断。

答案 2 :(得分:0)

如果你想保持这种编码方式,那么只需在阅读下一个字母之前添加一个支票。例如,

            letter1=TextIO.getChar();
            System.out.println("Do you awant to stop? Press 1 for Yes, otherwise press a different number.");
            numstop=TextIO.getInt();
            System.out.println(numstop);
            if (numstop==1) break;
            letter2=TextIO.getChar();
             ...