I ran this block of code(see below), and I'm expecting it to prompt the user for the name of the first superhero. However, Instead of taking the input from the user from the first line it immediately goes to the statement after the "else". Here is the console:
How many superheroes would you like?
3
Who is one of the superheroes?
Who is another superhero?
a
Who is another superhero?
b
Thank you
- 1.68
a - 2.78
b - 5.84
System.out.println("How many superheroes would you like?");
int n = input.nextInt();
String [] Super = new String[n];
for (int i = 0; i < n; i++) {
if (i == 0) {
System.out.println("Who is one of the superheroes?");
Super[i] = input.nextLine();
} else {
System.out.println("Who is another superhero?");
Super[i] = input.nextLine();
}