C# C# Collections Arrays Jagged Arrays

Michail Varouchas
Michail Varouchas
14,775 Points

BuildMultiplicationTable returned null

The table is costructed properly. It is printed out on the console as i shoud but I still get "BuildMultiplicationTable returned null". I'm stuck...

Math.cs
using System;

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
            int[][] table = new int[maxFactor + 1][];
            for (int i = 0; i < maxFactor; i++)
            {
                table[i] = new int[maxFactor + 1];

                for (int j = 0; j < maxFactor; j++)
                {
                    table[i][j] = i * j;
                }
            }

            for (int i = 0; i < maxFactor; i++)
            {
                for (int j = 0; j < maxFactor; j++)
                {
                    Console.Write(table[i][j]);
                }
                Console.WriteLine();
            }
            return table;



        }
    }
}

3 Answers

Steven Parker
Steven Parker
172,182 Points

The challenge asks you to return the table, it doesn't require you to print anything.

Also, you have allocated adequate space to create a table up to and including "maxFactor", but your loops stop short of it when setting the values.

Michail Varouchas
Michail Varouchas
14,775 Points
  1. I did "console.write" to see what the table has inside.
  2. I can't understand the part "your loops stop short of it when setting the values". What do you mean by that?
Michail Varouchas
Michail Varouchas
14,775 Points

Sorry! Your answer was really helpfull, I just figured it out. Thank you very much for you help Steven!