So like in the title it works until it loops back and ask both questions and whatever input I give gives an error. I tried switching the while loop to a for loop but same thing.
import java.util.Scanner;
public class PS4Grocery {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String itemNum = "";
int amount = 0;
double total = 0;
System.out.println(" Item Number | Price ");
System.out.println(" A123 | 100.50");
System.out.println(" A55 | 20.30");
System.out.println(" B750 | 40.20\n");
while (itemNum != "END") {
System.out.println("Enter an item: ");
itemNum = scan.nextLine();
System.out.println("Enter a quantity: ");
amount = scan.nextInt();
if(itemNum=="A123") {
total = total + (100.50 * amount);
}
else if(itemNum=="A55") {
total = total + (20.30 * amount);
}
else if(itemNum=="B750") {
total = total + (40.20 * amount);
}
}
System.out.println("Total Price: $" + total);
}
}