C# C# Collections Arrays Jagged Arrays

olu adesina
PRO
olu adesina
Pro Student 18,895 Points

help!! jagged arrays

Steven Parker this one is a real toughy

where im i going wrong

Math.cs
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;

        }
    }

}
Steven Parker
Steven Parker
168,137 Points

:bell: Hi, 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.

1 Answer

Florian Stegemann
Florian Stegemann
Full Stack JavaScript Techdegree Student 21,054 Points

Hey, 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.