Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Collections Arrays Jagged Arrays

olu adesina
olu adesina
23,007 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
220,925 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
seal-mask
.a{fill-rule:evenodd;}techdegree
Florian Stegemann
Full Stack JavaScript Techdegree Student 22,660 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.