I'm trying to write a program that takes input from the user, defining the number of rows and columns in an array, and then allows you to input elements one at a time. I don't know where to initialize my two arrays (a and b) because if I define the arrays inside my askUser method I can't figure out how to use it anywhere else, and if I define the arrays outside methods, I can't write to the array length. Any help is greatly appreciated.
public class Main{
public void askUser(){
System.out.print("How wide do you want the arrays to be: ");
width = sc.nextInt();
System.out.print("How tall do you want the arrays to be: ");
height = sc.nextInt();
for(int w = 0; w < height; w++){
for(int h = 0; h<width; h++){
length++;
}
}
int[][] a = new int[height][width];
int[][] b = new int[height][width];
for(int i = 0; i < height; i++){
for(int n = 0; n<width; n++){
System.out.print("What do you want ["+i+", "+n+"] to be: ");
a[i][n] = sc.nextInt();
b[i][n] = sc.nextInt();
}
}
}
public static void main(String[] args) {
Main obj = new Main();
obj.askUser();
}
}