-1
無論我輸入「y」還是「n」,程序都會退出while循環。我試着將一些==改爲.equals,但不管我進入循環的方式如何。當條件在循環中繼續時遇到循環退出
System.out.println("Just Cycling Caps provides three types of caps: Small caps – ID: 1 Price: $4.50, Medium caps – ID: 2 Price: $7.00, and Large caps – ID: 3 Price: $9.00");
continueOrder = "y";
//While loop to get items ordered
while(continueOrder == "y"){
//get desired cap size and quantity
System.out.println("Enter the ID of the item you would like");
capSize = reader.nextInt();
if(capSize == 1){
price = 4.5;
System.out.println("How many small caps would you like?");
quantityOfSmall = reader.nextInt();
priceOfSmall = quantityOfSmall * price;
}
else if(capSize == 2){
price = 7.0;
System.out.println("How many medium caps would you like?");
quantityOfMedium = reader.nextInt();
priceOfMedium = quantityOfMedium * price;
}
else if(capSize == 3){
price = 9.0;
System.out.println("How many large caps would you like?");
quantityOfLarge = reader.nextInt();
priceOfLarge = quantityOfLarge * price;
}
//Ask the user if they would like to continue ordering
System.out.println("Would you like to purchase another product? (y/n)");
continueOrder = reader.next();
continueOrder = continueOrder.toLowerCase();
}