Question: Java Question!!!: Modify the following code, Hello, The following code will ask a user to input a line number of Pascal's triangle and the program

Java Question!!!: Modify the following code,

Hello,

The following code will ask a user to input a line number of Pascal's triangle and the program will print this line number only. The program is done recursively. However, an error produces an does not output anything! I've tried everything but I cannot seem to get this program to run correctly. Can someone please help me out and modify this code so it will work properly?

The purpose of the program: ask a user to see a line of Pascal's triangle, and then prints this line only. the program uses recursion.

If possible, can you also add a comment where you fixed it so I can follow it?

thank you so much!!!!!

import java.util.Scanner; public class PascalRecursive { private int lineNumber, count; private int[] num; public PascalRecursive() { lineNumber = 1; } public void set (int n) { if (n < 1) lineNumber = 1; else lineNumber = n; } public int get() { return lineNumber; } private void pascal (int[] row) { if (count >= lineNumber) return; num = new int[row.length+1]; num[0] = 1; int i; for(i = 1; i < row.length; i++) num[i] = row[i-1] + row[i]; num[row.length] = 1; count++; pascal(num); return; } public int[] output() { count = 1; num = new int[count]; num[0] = 1; pascal(num); return num; } public static void main (String args[]) { int i, num; Scanner scan = new Scanner(System.in); System.out.println("Enter line number:"); System.out.println(""); num = scan.nextInt(); PascalRecursive t = new PascalRecursive(num); int[] result = t.output(); System.out.println("The " +t.get() + "line is"); for(i = 0; i < result.length; i++) System.out.print(result[i] + " "); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!