简体   繁体   English

在JAVA中用多个条件做while循环

[英]do while loop with multiple conditions in JAVA

The program keeps track of the product and quantity of the product in a do while loop and can only end if the user inputs the string "ZZZZ" and the integer 0. For example, inputting ZZZZ and 5 would not end the loop.程序在 do while 循环中跟踪产品和产品数量,只有在用户输入字符串“ZZZZ”和整数 0 时才能结束。例如,输入 ZZZZ 和 5 不会结束循环。 But somehow it's still ending.但不知何故它仍然结束。

 while (!itemcode.equals("ZZZZ") && (quantity != 0));

The output that I'm getting is我得到的输出是

Please enter the product code and quantity: ZZZZ 5

A105: 0    Price = 0.0
A207: 0    Price = 0.0
D671: 0    Price = 0.0
X111: 0    Price = 0.0
X902: 0    Price = 0.0
Total Price: $0.0

Which ends the loop but shouldn't.哪个结束循环但不应该。

我认为你真正想要的是:

while (!(itemcode.equals("ZZZZ") && quantity == 0));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM