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 trialSteven Toh
2,685 PointsJagged and MD array exercises failing despite solution working in Visual Studio
Hi,
For both of these exercises, I am getting the below message:
"The table should contain 6 rows and 6 columns"
I can run the same code in VS (albeit using console output commands) and I get the desired results. The jagged array code:
public static int[][] BuildMultiplicationTable(int maxFactor) { int[][] sheet = new int[maxFactor][];
for(int row = 0; row < sheet.Length; row++)
{
sheet[row] = new int[maxFactor];
for(int column = 0; column < sheet[row].Length; column++)
{
sheet[row][column] = row * column;
}
}
return sheet;
}
Guessing I am missing something obvious but the function is expecting the array itself to be returned, not a console output.
Thanks.
2 Answers
Steven Parker
231,248 PointsBe careful about testing a challenge in an external REPL or IDE.
If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.
You're really close, though. The issue is that your table is too small. To accommodate values up to and including maxFactor, the array dimensions (in both directions) will need to be maxFactor + 1
since the values begin at 0.
Kevin Gates
15,053 Pointsnamespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] sheet = new int[maxFactor+1][];
for(int row = 0; row < sheet.Length; row++)
{
sheet[row] = new int[maxFactor+1];
for(int column = 0; column < sheet[row].Length; column++)
{
sheet[row][column] = row * column;
}
}
return sheet;
}
}
}
Steven Toh
2,685 PointsSteven Toh
2,685 PointsHi Steve,
Doh! Always a simple answer. Thanks for the help.