private static int[] arr;
public static void inputarrays() {
Scanner scan = new Scanner(System.in);
System.out.println("length of an array");
int x = scan.nextInt();
arr = new int[x];
System.out.println("values of an array");
for(int n = 0; n < x; x++) {
arr[n] = scan.nextInt();
}
}
I looked up how to write code for getting an user input and creating an array like this one: Java - Creating an array from user input
It looks like my code is same as on the link's one which means it should work correctly. However, the scanner never closes when I enter the values of an array. I tried scan.close()
, but it did not work. Also, I cannot use try&exception for this one.