I'm looking to print out a number matrix using parallel arrays. I want to find a way to ensure that each number is printed out with a proper amount of digits, based on how long the longest digit number in the array is.
So for example:
rows = r;
cols = c;
int[][] matrix = new int[rows][cols];
for (int x = 0; x < cols; x++)
{
for (int y = 0; y < rows; y++)
{
matrix[x][y] = (x*y);
}
}
If I choose to set cols = 101
and rows = 101
, my largest number will be 10000
. How can I set this program up so that at matrix[1][1] = (1*1)
my output will be 00001
, instead of just 1
?