0
  public class PascalRecursion
  {
  public int[] pascalTriangle(int rowNum, int colNum, int pos)
  {
  colNum = rowNum + 1;
  int[] result = new int[colNum];
  pos = 1;
  if (rowNum == 0)
  {
  result[0] = 1;
  for (int list : result)
  {
    System.out.print(list);
  }
  return result;
  }
  if (rowNum == 1)
  {
  result = new int[]
  {1, 1};
  for (int list : result)
  {
    System.out.print(list);
    }
     return result;
   }
   if (rowNum > 1)
    {
     if (pos < colNum)
     {
     result[pos] = rowNum;
     result[0] = 1;
     result[result.length - 1] = 1;
     result[result.length - 2] = rowNum;
     return pascalTriangle(rowNum = rowNum * (colNum - pos) / colNum,    \  colNum,
                          pos = pos + 1);
      }
      for (int list : result)
      {
        System.out.print(list);
      }


    }
    return result;

  }
}

So I have this so far, I'm fairly new to recursion, and have gotten stuck, I am supposed to print the Nth row of pascals triangle, but for some reason no matter what number I input, it gives me 1,1(unless I input 0 of coarse). Any help would be much appreciated!

  • Possible duplicate of [Printing Pascals Triangle (recursive) (JAVA)](http://stackoverflow.com/questions/26749516/printing-pascals-triangle-recursive-java) – A_Di-Matteo Dec 10 '15 at 22:35
  • When you do recursion you should be building on the previous values e.g. passing the previous row to the next recursive call. Building the results from scratch each time is not recursive. – Peter Lawrey Dec 10 '15 at 23:04
  • Ok by this you mean, I should build my second row off my base case?Then build my next row off the previous row (row off the base case)?@Peter Lawrey – Jaden Hambley Dec 11 '15 at 00:46

0 Answers0