Pascal's Triangle with Recursion
Hey everyone, I am new here. I have a Computer Science 2 Assignment due in a few days dealing with printing out the Nth row of pascal's triangle using a recursive method. Here is what I have so far:
class PascalTriangle {
public static int[] Pascal(int num){
int[] ans = new int[num];
if(num==1){
ans[0]=1;
}
else {
int[] pre = Pascal(num-1 + num);
}
return ans;
}
public static void main(String[] argv) throws IOException {
BufferedReader inBuf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the row number: ");
StringTokenizer T = new StringTokenizer(inBuf.readLine());
while(T.countTokens()!=0){
int num = Integer.valueOf(T.nextToken()).intValue();
System.out.println("Row "+num+" of the Pascal Triangle is:");
int[] row = Pascal(num);
for(int i=0; i<num; i++)System.out.print(row[i]+"\t");
System.out.println();
System.out.print("Enter the row number: ");
T = new StringTokenizer(inBuf.readLine());
}
}
The problem is within my Pascal method, I can't quite figure out how to determine the rows using recursion. I have used recursion for a few assignments before this, so I understand the concepts. I was hoping someone would be willing to POINT ME into the right direction. Please don't give me an answer. By the way, my Professor said that it should take no more than 4-5 lines in the method.