I’m trying to make a 5 by 10 table using a double array. The first box should be blank, then the rest numbered 2-50.
I have this so far but it is not working.
int array[][] = new int[5][10];
for(int row=1; row<5;row++){
for(int col=1;col<10;col++)
array[row][col] = row*col;}
System.out.println(array);
row * colcannot give you consecutive numbers from2 to 50. And in your code, you are not just leaving thefirst box, but you are leaving outfirst rowandfirst columncompletely.You should run the loop normally from
0 to max. And for[0][0], don’t print anything.Also, for printing from
2 to 50, just have a count variable which starts with2, and after printing it, increment it by1.Here’s the modified code: –
OUTPUT : –
NOTE: –
Since you want your
first boxto be blank, you can’t useArrays.toStringhere. You would have to use one more loop, and print your array in simple ways. And when your indices are[0][0], justsysout("");