Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialWilliam Millington
2,440 PointsI need to include the [0,0] row and column and I can't work out how.
I have coded up a basic multiplication matrix. However, to complete the challenge I need to include the first row and columns of 0. I have tried everything that I can think of. Any help to solve this (fairly simple issue I can't crack) is greatly received.
Thanks
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] multiplicationTable = new int[maxFactor][];
for (int row = 1; row <= maxFactor; row++)
{
multiplicationTable[row - 1] = new int[row];
for (int col = 1; col <= row ; col++)
{
multiplicationTable[row - 1][col - 1] = row * col;
}
}
return multiplicationTable;
}
}
}
1 Answer
Steven Parker
231,248 PointsThe overall function structure is good, but you have some values issues:
- the loops should start at 0 instead of 1
- the rows will need to have
maxFactor
plus one items - the columns will need to be the same size as the rows (instead of the row itself)
- the indexes need to remain inside the range
William Millington
2,440 PointsWilliam Millington
2,440 PointsThank you again for your help, and thanks for allowing me to learn where I went wrong. Much appreciated.