【发布时间】:2017-04-27 20:48:32
【问题描述】:
如果这是愚蠢的,请原谅我,因为我在 Java 方面相对较新
当前程序可以编译,但是它完全跳过了 while 循环。
//Defined Variables
static boolean breaker = false;
static boolean breaker2 = false;
static boolean tf = false;
static boolean tf2 = false;
static int code = 0;
static int random = -8;
static String input = "Nothing here";
System.out.println("1");
//Resetting variables to control while loop
breaker = false;
tf = true;
random = (int)(Math.random() * 100 + 1);
while(breaker2 = false)
{
input = i.nextLine();
if (random >= 90)
tf = false;
if (input.equals("N") || input.equals("n"))
{
System.exit(0);
}
else
{
if (input.equals("Y") || input.equals("y"))
{
tf2 = false;
breaker2 = true;
}
else
{
//Text output
}
}
}
System.out.println("3");
输出:
1
3
除了 while 循环之外的所有内容都被执行。我以前遇到过这个问题,并从头开始编写循环。它有同样的问题。 (“1”“2”和“3”用于标记执行了什么。)
【问题讨论】:
-
while(breaker2 = false)应该是while(breaker2 == false)或while(!breaker2)
标签: java while-loop