C# C# Collections Arrays Jagged Arrays

From the instructions, it is not clear to me what should happen if maxFactor < 0.

Can someone please let me know what I am missing? I am getting this error: BuildMultiplicationTable returned null Thanks!

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

           if (maxFactor > 0) {
                int [][] table = new int[maxFactor + 1][];                
                for (int row = 0; row < maxFactor; row++) {
                    table[row] =  new int[maxFactor +1];
                    for (int col = 0; col < maxFactor; col++) {
                        table[row][col] = row * col;
                        System.Console.Write(table[row][col]);
                    }
                    System.Console.WriteLine();

                }
                return table;

            } else return new int[0][];
        }
    }
}

1 Answer

Steven Parker
Steven Parker
182,341 Points

:point_right: Your table contents are missing a row and column.

Your loops should test for "<=" instead of just "<", since you want to include the maxFactor row and column. Also, your Write/WriteLine's may be confusing the checker. And you don't need to make a special case for values <= 0. It's not a bad idea, but not required by the challenge.