C# C# Collections Arrays Jagged Arrays

Eilam Maimoni
Eilam Maimoni
9,174 Points

cant understand how to solve the challenge...

I tried to solve this problem but couldn't understand how. Thanks for any help!

Math.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
            int[][] sheet = new int[maxFactor][];

            for (int rowI = 0 ; rowI <= maxFactor ; rowI++)
            {
                sheet[rowI] = new int[maxFactor]; 

                for (int colI = 0 ; colI <= maxFactor ; colI++)
                {
                    sheet[rowI][colI] = colI;
                }
            }
             System.Console.WriteLine(sheet);
            return sheet;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
149,029 Points

You got pretty close! But the size of an array must be one more than the largest index you will use with that array. This would apply to the declarations for both dimensions.

Also remember this is a multiplication table. So the contents of any particular cell would be the column index multiplied by the row index.