I am currently trying to have a recurring loop where the user inputs values to add to a linked list. But every time there is a space within one of the input values it causes the loop to skip the flag nextLine() input.
Here is the code:
while(true)
{
System.out.println("Please enter product name: ");
productName = input.nextLine();
System.out.println("Please enter the Price: ");
price = input.nextDouble();
productList.addProduct(productName, price);
System.out.println("Are you done with this transaction? Y/N: ");
stopFlag = input.nextLine();
if(stopFlag.equalsIgnoreCase("y"))
break;
}
If I input "villainous" as the first string and then 22.99 as the double value it works fine. Then I can input either y/n to exit. But! if I say input "Villainous exp" as the first string, the second double input works fine, then the last one skips and I get an output like:
Please enter product name:
Villainous Exp
Please enter the Price:
22.99
Are you done with this transaction? Y/N:
Please enter product name:
I don't know how to make it not skip the bottom input or understand why it is even doing so.