简体   繁体   中英

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. 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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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