2014-07-03 31 views
0

这是我的代码:如果用户这样说让我的代码再次循环,又怎么样?

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; 
      } 
+0

的,什么是不工作? – MadProgrammer

+0

构造时使用 – HJK

回答

1

在这里:你有一个混合了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 
} 
1

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

int orderDone = 1; 
//declare variables 
    while(true){ 
     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){ 
     break; 
     } 

,如果你要循环再一次,只要将同时在真实,如果用户想退出只使用断码;

0

这里使用的解决方案,同时做到:

int orderDone = 0; 

Scanner scanner = new Scanner(System.in); 

do{ 
    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 

    System.out.println("Would you like to make another order? (0 - yes 1 - no) "); 
    orderDone = scanner.nextInt(); 

} 
while(orderDone == 0); 
相关问题