I am trying to create a 2d table that asks for user input to create table size, adds all the numbers across each row, and creates the next row by multiplying by the first row. Here's what I have and it's now giving me an "Exception in thread "main" java.lang.NullPointerException" error.
Any help is greatly appreciated!
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int[][] table = new int [11][];
int[] row = new int[0];
System.out.println("Enter integer to create table size: ");
int numRows = input.nextInt();
for (int i=0; i<table.length; i++){
for (int j=0; j<table[i].length; j++) {
row = rowTotals(row);
table[i] = new int [i*2];
System.out.print(table[row][j] + " ");
}
}
}
public static int[] rowTotals (int[] prevRow) {
int num = 1;
int[] row = new int[prevRow.length];
row[0] = 1;
for (int i=1; i<row.length; i++) {
row[i] = prevRow[i];
num++;
}
return row;
}
}