I'm writing a program that asks how many users are going to use it, based off that response it creates an array of String type holding the names of each user. The problem I'm running into is that when I execute the for-loop that stores each name into the String type array, it prints out the statement twice before accepting a string input. Anyone know what I'm doing wrong?
Scanner input = new Scanner(System.in);
System.out.print("Please enter the number of users: ");
int numUser = input.nextInt();
String[] userArray = new String[numUser];
for (int i = 0; i < numUser; i++) {
System.out.print("For user " + (i+1) + ", please type your username followed by enter: ");
String inputUsername = input.nextLine();
userArray[i] = inputUsername;
}
for (int i = 0; i < numUser; i++) {
System.out.println(userArray[i]);
}
}
OUTPUT
notice in the image of my output that my statement is outputted twice on the same line and on the second statement I can finally start inputting names storing them into the array. Also, I have a for-loop that displays the names, notice that the first name is blank and after that it displays the rest of the names. Image of the output of my Java program after it's been ran