Name: Anonymous 2013-11-24 9:06
So im making this boolean array in Java which is the result of the logical AND operation on two boolean values from different boolean arrays. I keep getting a NullPointerException, though, and dont know why. Can anyone point me in the right direction?
code:
code:
public static boolean[][] boolAnd(boolean[][] tablea, boolean[][] tableb) {
boolean[][] andtable, table1, table2;
int row, col, smallest;
row = (tablea.length >= tableb.length)?(tablea.length):(tableb.length);
andtable = new boolean[row][];
table1 = new boolean[row][];
table2 = new boolean[row][];
smallest = (tablea.length <= tableb.length)?(tablea.length):(tableb.length);
for (row = 0; row < smallest; row++) {
col = (tablea[row].length >= tableb[row].length)?(tablea[row].length):(tableb[row].length);
andtable[row] = new boolean[col];
table1[row] = new boolean[col];
table2[row] = new boolean[col];
}
for (row = 0; row < tablea.length; row++) {
for (col = 0; col < tablea[row].length; col++) {
table1[row][col] = tablea[row][col];
}
}
for (row = 0; row < tableb.length; row++) {
for (col = 0; col < tableb[row].length; col++) {
table2[row][col] = tableb[row][col];
}
}
for (row = 0; row < andtable.length; row++) {
for (col = 0; col < andtable[row].length; col++) {
andtable[row][col] = (table1[row][col] && table2[row][col]);
}
}
return(andtable);
}