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 trialDaren Davis
6,929 PointsCode seems valid... but getting "The table should contain 6 rows and 6 columns error" any suggestions?
test code with...
namespace CSharpcollections
{
class Program
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] table = new int[maxFactor][];
for(var i = 0; i < maxFactor; i++)
{
table[i] = new int[maxFactor];
for(int j = 0; j < maxFactor; j++)
table[i][j] = i * j;
}
return table;
}
public static void Main()
{
var newTable = BuildMultiplicationTable(6);
foreach (var row in newTable)
{
System.Console.WriteLine();
for(int i = 0; i < row.Length; i++)
{
System.Console.Write(row[i] + " ");
}
}
}
}
}
Math.cs
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] table = new int[maxFactor][];
for(var i = 0; i < maxFactor; i++)
{
table[i] = new int[maxFactor];
for(int j = 0; j < maxFactor; j++)
table[i][j] = i * j;
}
return table;
}
}
}
1 Answer
Steven Parker
231,198 PointsYour array is a bit too small.
To create a table that goes up to and including maxFactor
, your loops should ues "less than or equal" ("<=
") to compare instead of just "less than" ("<
"). Also, since the array indexes start at 0, the sizes must be larger by one ("maxFactor + 1
").
Daren Davis
6,929 PointsDaren Davis
6,929 PointsYep, got it thanx.