Hi folks new to Java and am making slow progress. I am trying to populate a 2D array with random numbers before I add the rows and columns. So far I can create the array, display it and I'm pretty sure I have the addition bit sorted. But I'm getting an outofboundsexception when I try to fill it with random numbers. Where am I going wrong?
public static void main(String[] args)
{
//create the grid
final int row = 9;
final int col = 9;
int [][] grid = new int [row][col];
//fill the grid
for (int i=0; i<grid.length; i++)
grid[i][grid[i].length] = (int)(Math.random()*10);
//display output
for(int i=0;i<grid.length; i++)
{
for(int j=0; j<grid[i].length; j++)
System.out.print(grid[i][j]+"");
System.out.println();
}
int sum = 0;
for (int i = 0; i < grid.length; i++) {
System.out.println("This row sums up to: " + sum);
for (int j = 0; j < grid[i].length; j++) {
sum += grid[j][i];
}
System.out.println("This column sums up to: " + sum);
}
}