So, I know this is probably a really stupid question, I am a beginner trying to learn Java basics and I have a problem with string array that I can't quite figure out. When I try to enter words into string array and the number of words is set by user (for example 5) I always can enter one less word (for example 4 instead of 5). My code is down below.
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the number of words");
int n = scan.nextInt();
String arr[] = new String[n];
System.out.println("Please enter the words");
for (int i = 0; i < arr.length; i++) {
arr[i] = scan.nextLine();
}
for (int i = 0; i < arr.length; i++) {
System.out.print(" " + arr[i]);
}
}