java - 未读取变量

标签 java variables boolean

代码中 (cancel1 = 2) boolean 值“cancel”未被读取的部分:

while (done !=0){
  pizzaChoice = readInt ("Choose the type of pizza you wish to order");
  double quantity = readInt ("How many " + type[pizzaChoice] + " pizzas do you wish to buy (Maximum pizzas per order is 5)");   

  if(quantity >= max){
    System.out.println("Sorry you cannot order more than five pizzas");


    if ((quantity - max) <= 0){
      double pizzasLeft = max - quantity;

      System.out.println("You can still order " + pizzasLeft + " pizzas");

      pizzasLeft2 = pizzasLeft2 - pizzasLeft;

下一个if循环就是问题所在

              if (pizzasLeft2 <= 0){
                boolean cancel = true;
                int cancel1 = readInt("Press 2 to cancel your order and start again"); 
                if(cancel1 == 2){
                  cancel = false;
                }

              }
            }
          }

          done= readInt ("Press 0 if you are done or press 1 to make another pizza order");
          double total1 = quantity*price[pizzaChoice];
          total2 = total2 + total1;
        }

最佳答案

cancel相关的代码对我来说似乎是正确的。
我建议您检查具有此值的 block 。 是否满足首先进入if block 的条件?
提示是另一个取消全局变量可能会对其角色产生歧义。

关于java - 未读取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10581426/

相关文章:

C# - 通过引用传递值类型的好而灵活的方法?

java - 如何在 Apache - CXF 客户端的上传文件后调用中发送 multipart/formData?

java - Vaadin 14 - 在嵌套布局中使用时网格不显示/填充

java - 在单核系统上拥有多个线程还能提高性能吗?

elasticsearch - Elastic Multimatch Query与文档不匹配

c++ - 递归和返回 boolean 值

java - Setter - 检查值

java - 检测 twitter4j 的关闭流

JavaScript 问号? : logical syntax, 防御性编程

variables - 如何在 TWIG 宏中访问模板变量?