What I'm trying to achieve is:
- Create an array, and define its length with user input (scanner). ✓
- Loop through the array to fill in its values. ✓
- After defining its length and filling in the values according to the length, printing the whole array. X
I wasn't able to achieve number 3. Can someone help me? I simply need to print the array.
This is my code:
package arrayinputoutput;
import java.util.Scanner;
public class ArrayInputOutput {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x;
int[] test;
System.out.println("How long should the array be?");
x = input.nextInt();
for (int i = 0; i < x + 1; i++) {
input.nextLine();
System.out.println("Please fill in position " + i + ":");
i = input.nextInt();
}
//System.out.println(test[]);
}
}