I'm new to Java and I'm trying to get a good grasp on 2D arrays. In this code, I'm trying to print out the sum of 2 randomly generated dice. I'm having a great deal of trouble with it so any guidance would be much appreciated. Here's what I have so far...
public class chance
{
public static void main(String[] args)
{
int dice, dice1, dice2;
dice1 = ((int)(Math.random() * 6)) +1;
dice2 = ((int)(Math.random() * 6)) +1;
dice = dice1 + dice2;
int table[][] = new int[3][3];
int sum = 0;
int i, j;
for (i = 0; i < 3; i++)
{// 3 rows: i = 0,1,2
for (j = 0; j < 3; j++)
{
sum += table[i][j];
}
}
for (i = 0; i < table.length; i++)
{
for (j = 0; j < table[i].length; j++)
System.out.print(table[i][j] + " ");
System.out.println( );
}
}
}