int number = keyboard.nextInt();
String [][] myArray = new String[number][1]
for (int i = 0; i < x; i++)
{
System.out.println("Enter food name: ");
myArray[i][0] = keyboard.nextLine();
for (int j = 0; j < 1; j++)
{
System.out.println("Enter the type of this food: ");
myArray[i][j] = keyboard.nextLine();
}
}
Here is my code for what I am about to ask. I want it to print out these outputs when I run this program:
Enter food name:
(where user type his or her input)
Enter the type of this food:
(where user type his or her input)
(My problem is it prints out this instead for the first loop:)
Enter food name:
Enter the type of this food:
(where user type his or her input)
With no way of entering the food item. After the first loop, then the program is back to normal with the output I want, but how do I change the code so that the first loop will take in user input for "enter food name: "?
Thanks in advance.
Edit: sorry for not seeing that question beforehand but that one is not about a for loop so if I enter an empty string before the next input, my loop will not work. Is there any fix to this?
Edit: Got it to work. Thanks everyone.