Question
Here is the question: Here is my code: public class Assignment5Q3 { public static void main(String[] args) { PascalsTriangle triangle = new PascalsTriangle(9); triangle.printTriangle(); }
Here is the question:
Here is my code:
public class Assignment5Q3 { public static void main(String[] args) { PascalsTriangle triangle = new PascalsTriangle(9); triangle.printTriangle(); } }
class PascalsTriangle { private int line; //private int[][] triangle; /**Constructor*/ public PascalsTriangle(int line) { this.line = line; //triangle = new int[line][line]; } /**print all lines*/ public void printTriangle() { printNthLineAndReturn(line, line); }
/** get numbers from current row, as int[]*/ private int[] printNthLineAndReturn(int indexOfRow, int line) { if (indexOfRow == 1) { int[] one = new int[1]; one[0] = 1; String whitespace = returnBlank(line - indexOfRow); System.out.print(whitespace); printArray(one); return one; } int[] row = new int[indexOfRow]; int[] previousRow = printNthLineAndReturn(indexOfRow - 1, line); row[0] = 1; row[indexOfRow - 1] = 1; for (int index = 1; index
String whitespace = returnBlank(line - indexOfRow); System.out.print(whitespace); printArray(row); return row; } /**print the numbers in the int[]*/ private void printArray(int[] numArray) { //System.out.print(numArray.length + ": "); for (int index = 0; index
Please fix any issues in my code or comment if it's all correct. Thank you.
3. Design and implement a recursive program to determine and print up to the Nth line of Pascal's Triangle, as shown below. Each interior value is the sum of the two values above it. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 1 Hint: You should use an array to hold the values for a given line. It is not necessary to format the output exactly as presented above. One recursive approach is: Tan, 0) = Tan, n) = 1 Tan, d) = T(n-1, d - 1) + T(n-1, d)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started