I'm trying to create a program where the user can create an array using scanner. In this example, if the first input is 4, an array with the length of 4 is then initialized. However, in the next part, the scanner is asking for 5 inputs instead of 4. If the next inputs are 1 2 3 4 5, the final output will be [2,3,4,5]. I'm not sure why it's asking for 5 inputs instead of 4. Can someone tell me what I did wrong?
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] numbers = new int[n];
int input = s.nextInt();
for (int i = 0; i < n; i++) {
numbers[i] = s.nextInt();
}
System.out.println("---------");
for (int x : numbers) {
System.out.print(x);
}
}
}
int input = s.nextInt();.