java - 如果用户这么说,如何让我的代码再次循环?

标签 java loops variables block replay

这是我的代码:

public class Pizza {
    public static void main(String[] args) { 

        int orderDone = 1;
    //declare variables
        while(orderDone == 1){
          int done = 1;
          double total2 = 0;
          final int DELIVERY_COST = 3;
          double pizzaPrice = 8.50;
          String customerAddress = null;
          String customerNumber = null;
          int pizzaQuantity = 0;

    //my code

    orderDone = readInt("Would you like to make another order? (0 - yes  1 - no) ");
          if(orderDone == 1){
            orderDone = 2;
          } else {
            done = 0; 
          }

最佳答案

这里:你混淆了 1 和 0。另外,最后没有使用额外的 if 和 else 语句。

public class Pizza {
public static void main(String[] args) { 

    int orderDone = 0;
//declare variables
    while(orderDone == 0){
      int done = 1;
      double total2 = 0;
      final int DELIVERY_COST = 3;
      double pizzaPrice = 8.50;
      String customerAddress = null;
      String customerNumber = null;
      int pizzaQuantity = 0;
      //my code 
      orderDone = readInt("Would you like to make another order? (0 - yes  1 - no) ");
    }
  }
 // reset of the code
}

关于java - 如果用户这么说,如何让我的代码再次循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24544363/

相关文章:

java - Android手持设备和Wear通信不一致

python - 迭代列表切片

javascript - 两个 div 同一类,仅获取该 div 的标题

Java 安装程序。如何设置Windows系统路径?

java - Facebook 身份验证不会从第二次开始调用 onActivityResult

java - 对 hibernate 应用程序使用@Transactional 注释导致错误

java - 以编程方式检测内存泄漏

python - 在多种条件下合并来自多个数据帧的数据

arrays - Bash:在 FOR 循环中跳出 IF 循环

使用 pthread 时,使用全局变量的 C++ 显示比指针慢 100%?