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 trialCalvin Secrest
24,815 PointsI'm confused with it's multiplication table
Return a multiplication table consisting of a 2D multidimensional array. The table should contain all of the products of integers from 0 to maxFactor. For example, if maxFactor is 3 the resulting multiplication table should contain the following: 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9
Bummer! Your code could not be compiled. Please click on "Preview" to view the compiler errors. Restart Preview Get Help Recheck work Math.cs
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[,] BuildMultiplicationTable(int maxFactor)
{
for (int i = 0; i < array.Length; i++)
{
System.Console.Write("maxFactor({0}): ", i);
}
}
}
}
7 Answers
Philip G
14,600 PointsHi Calvin,
there were multiple errors in your code. First, the challenge tells you to use a jagged array(int[][]
), not a multidimensional(int[,]
) one. Also, you have to declare and return an array instead of printing the results to the Console.
Well, you can have a look at this code, which should work for the challenge:
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] arr = new int[maxFactor + 1][];
for (int x = 0; x <= maxFactor; x++)
{
arr[x] = new int[maxFactor + 1];
for (int y = 0; y <= maxFactor; y++)
{
arr[x][y] = x * y;
}
}
return arr;
}
}
}
I would recommend you to study the structure instead of just copy&paste. If you get stuck, you can review the videos, and of course feel free to ask me!
Best Regards, Philip
Justin Blankinship
5,087 Pointsnamespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[,] BuildMultiplicationTable(int maxFactor)
{
int[,] arr = new int[maxFactor + 1, maxFactor +1];
for (int x = 0; x <= maxFactor; x++){
for (int y = 0; y <= maxFactor; y++)
{
arr[x, y] = x * y;
}
}
return arr;
}
}
}
Andrei Li
34,475 PointsI am just happy! Here is my solution:
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[][] BuildMultiplicationTable(int maxFactor)
{
int[][] result = new int[maxFactor+1][];
for(int i=0; i <= maxFactor;i++)
{
result[i] = new int[maxFactor+1];
for(int j = 0; j <= maxFactor; j++)
{
result[i][j] = i*j;
}
}
return result;
}
}
}
Terry McDuffie
12,786 Points@CalvinSecrest did you ever complete this challenge?
Calvin Secrest
24,815 PointsI did thanks for checking on my issued
Terry McDuffie
12,786 PointsI'm having trouble how did you get it to compile Calvin Secrest
Ricardo Ferreira
9,694 PointsQuestion, is the maxFactor + 1 added inside the [] because we count from zero?
Daniel Yates
7,653 PointsCorrect
HIDAYATULLAH ARGHANDABI
21,058 PointsDear Cavin
using System.Collections.Generic;
using System;
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static List <int> GetPowersOf2 (int UpperLimit)
{
var PowersOf2List = new List <int> ();
for (int index = 0; index < UpperLimit + 1; index++)
{
PowersOf2List.Add ( (int) Math.Pow (2, index) );
}
return PowersOf2List;
}
}
}
Calvin Secrest
24,815 PointsCalvin Secrest
24,815 PointsThanks for you assistance
Elfar Oliver
3,924 PointsElfar Oliver
3,924 PointsI tried reading through and maybe understood a bit, but could you explain a few things for me? If you're still on here 5.5 years later that is