I'm trying to modify the name of a product in an array, but using my code it will just go to "input category" and then "input price" without even reading the "Input name of new product" line. I believe it has something to do with nextLine(), but can't figure out why it does work with the other options and not on that line. Would really appreciate any advice.
if (option == 2) {
int position;
System.out.println("Modify Inventory");
System.out.println("Code\tProduct");
calculations.printData(products, categories, prices);
System.out.print("Input the code of the product to modify: ");
position = input.nextInt();
for (int i = 0; i < products.length; i++) {
if (i == position) {
System.out.println("Input the name of new product: ");
products[i] = input.nextLine();
System.out.println("Input Category: ");
categories[i] = input.nextLine();
System.out.print("Input price: ");
prices[i] = input.nextDouble();
System.out.println();
}
}