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 trialolu adesina
23,007 Pointshelp!! jagged arrays
Steven Parker this one is a real toughy
where im i going wrong
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] arr = new int[maxFactor][];// creating array of arrays.number of rows depend on maxfactor
for (int rowindex = 0; rowindex < arr.Length; rowindex++)
{
arr[rowindex] = new int[maxFactor];//creating colums in each row using maxfactor
for (int colIndex = 0; colIndex < arr[rowindex].Length; colIndex++)
{
arr[rowindex][colIndex] = rowindex * colIndex;//initialising values for each num
}
}
return arr;
}
}
}
1 Answer
Florian Stegemann
Full Stack JavaScript Techdegree Student 22,660 PointsHey, you're almost there with your code but take another look at the example in the challenge. For a maxFactor of 3 an array with a size of 4 by 4 is returned, because you want all the products from 0 up to and including 3. By just supplying maxFactor as the size for the arrays, you're only getting the products from 0 up to but excluding maxFactor, which means your Arrays are currently always to small by one element.
Steven Parker
231,248 PointsSteven Parker
231,248 PointsHi, I was alerted by your tag. But it looks like Florian beat me to it, and I agree with his analysis.
Just expand your array sizes by one and you'll pass the challenge.