I am a novice to java. Im trying to write a two-dementional array that writes out a lottery ticket (6 integers) 10 times
int[][] lottery = new int[6][10];
for (int i=0; i < lottery.length; i++)
for (int j=0; j < lottery[0].length; j++)
lottery[i][j] = (int)(50.0 * Math.random());
for (int i=0; i < lottery.length; i++)
for (int j=0; j < lottery[0].length; j++)
{
/*if i < lottery.length
System.out.print(lottery[i][j] + " ");
else
System.out.println(lottery[i][j]);*/
}
How do I write it out as 10 rows of 6 integers
23 12 31 49 3 17
9 1 22 13 36 50
.
.
.
Your array is backwards. If you want to be able to output 10 rows of 6 numbers with the nested for loops that you have, you would need the array to be
int lottery[][] = new int[10][6];Then to output it, you’d simply need to do:
The call to System.out.print will print the text without a new-line character so you can keep appending to the same line.