Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,198 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!