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;
}
}
所以到目前为止,我有这个,我对递归很新,而且已经卡住,我应该打印第三行帕斯卡三角形,但出于某种原因无论我输入什么数字,它都给出了我1,1(除非我输入0粗)。任何帮助将不胜感激!