user11353658
user11353658

Reputation:

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.

Upvotes: 0

Views: 64

Answers (1)

Ryan
Ryan

Reputation: 1760

I think what you really want is this:

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

Upvotes: 1

Related Questions