How to build a 2D int array from a string?

advertisements

I am trying to build a 2d int array from a string array. I parsed the strings from an input file so that each string had the numbers for the rows of the int array. I'm not sure what I am doing wrong. Any ideas? relevant code:

String arrayA[] = ["",
                  "1 2 -2 0 ",
                  "-3 4 7 2 ",
                  "6 0 3 1 "]
String aryA[] = new String[arrayA.length];
int rowsA[] = new int[3];
int colsA[] = new int[4];
int a[][] = new int[rowsA.length][colsA.length];
String row1A[];
for(int i = 0, j = 1; i < rowsA.length; j++, i++){
    row1A = arrayA[j].split(" ");
    System.out.println(row1A[j]);
    try {
        rowsA[i] = Integer.parseInt(row1A[i]);
    }
    catch (NumberFormatException e) {
        System.out.println("Input was not an int");
    }
}


Arrays use braces rather than square brackets

String[] arrayA = { "", "1 2 -2 0 ", "-3 4 7 2 ", "6 0 3 1 " };