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 trialRui Martinho
21,221 PointsC# Collection, jagged array challenge 1
My code is not validating, and i am receiving the below error message: "The table should contain 6 rows and 6 columns"
My code, is
" namespace Treehouse.CodeChallenges { public static class MathHelpers { public static int[][] BuildMultiplicationTable(int maxFactor) { int[][] arr = new int[maxFactor][];
for (int i = 0; i < arr.Length; i++)
{
arr[i] = new int[maxFactor];
for (int j = 0; j < arr[i].Length; j++)
{
arr[i][j] = new int();
arr[i][j] = i * j;
}
}
return arr;
}
}
} "
Can someone help?
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] arr = new int[maxFactor][];
for (int i = 0; i < arr.Length; i++)
{
arr[i] = new int[maxFactor];
for (int j = 0; j < arr[i].Length; j++)
{
arr[i][j] = new int();
arr[i][j] = i * j;
}
}
return arr;
}
}
}
1 Answer
Steven Parker
231,248 PointsYour array is a bit too small.
Remember that the first row and column of the array will be 0, so to accommodate factors up to and including maxFactor, you'll need an array size of maxFactor + 1
.
Rui Martinho
21,221 PointsRui Martinho
21,221 PointsPerfect.
It validated.
Thank you, Steven Parker