1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lemur [1.5K]
4 years ago
12

Implement a program to recursively print out Pascal's Triangle:

Computers and Technology
1 answer:
Deffense [45]4 years ago
5 0

Implement a program to recursively print out Pascal's Triangle:

1: 1

2: 1 1

3: 1 2 1

4: 1 3 3 1

5: 1 4 6 4 1

6: 1 5 10 10 5 1

7: 1 6 15 20 15 6 1

8: 1 7 21 35 35 21 7 1

9: 1 8 28 56 70 56 28 8 1

10: 1 9 36 84 126 126 84 36 9 1

Important questions to ask yourself:

What is the base case?

What is the recursive case?

What should the method return?

Your class should be called Pascal and have one static

method called triangle that takes an argument 'n' and

returns the n-th line of Pascal's Triangle.

Here is the code for the main method that

will call the method you write.

public class Main {

public static void main(String[] args) {

int n = args.length == 1 ? Integer.parseInt(args[0]) : 1;

for (int i = 1; i <= n; ++i) {

int[] arr = Pascal.triangle(i);

System.out.print((i < 10 ? " " : "") + i + ": ");

for (int j : arr) {

System.out.print(j + " ");

}

System.out.println();

}

}

}

class Pascal {

public static int[] triangle(int n) {

{code goes here}

}

}

Result should look like Pascal's Triangle above and use recursive method for code. Please copy

You might be interested in
4.2.10: Multiplication Table: Create a program using a for loop which will print out the 4’s times table through 10.
nordsb [41]

I included my code in the picture below. Best of luck.

6 0
3 years ago
Templates contain common layout and formatting that can save you time by not having to recreate documents from scratch. True or
Anarel [89]
True because i had heard my friend doing her homework and i was helping her study
4 0
3 years ago
Please help! I have no idea how to make a chart like this in Google Sheets, any help is appreciated! :)
Alecsey [184]

1. Open Google Sheets

2. Click Insert Tab

3. Click Drawing

4. Click Shapes (click the shape like in the picture.)

5. Click The line with the two dots. ( to add the lines )

6. Add text box


I hope this helped!


5 0
4 years ago
Memes are life dont delete if u do then u know im right
soldier1979 [14.2K]

Answer:

oof  ur right

Explanation:

4 0
4 years ago
Read 2 more answers
Which two benefits can be expected from KCS adoption if universal Containers wants to implement best practices for its customer
drek231 [11]

Answer:

B. A knowledge article life cycle that evolves based on usage and demand.

Explanation:

As new information is gathered on the product and the type of issues that customers encounters, the knowledge article can be updated to inform the customer on how to handle their problem.

3 0
4 years ago
Other questions:
  • If your vehicle leaves the pavement for any reason, remember to take your foot off the gas pedal, hold the wheel firmly, and
    12·2 answers
  • He following is a string of ASCII characters whose bit patterns have been converted into hexadecimal for compactness: 4A EF 68 6
    12·1 answer
  • What is the size of the opening in the camera that the light passes through?
    9·2 answers
  • Give a logical expression with variables p,q, and r that is true if p and q are false and r is true and is otherwise false.
    5·1 answer
  • Write a SELECT statement that selects all of the columns for the catalog view that returns information about foreign keys. How m
    6·1 answer
  • Which key temporarily activates the Hand tool?​
    6·1 answer
  • Write Java code that creates an array of n integers myArray, by taking n integers from the user with duplications, and do the fo
    8·1 answer
  • PLEASE HELP WILL GIVE BRAINLIEST!!!’
    15·1 answer
  • Vhat is the result when you run the following program?
    6·1 answer
  • Which ipconfig command switch would a technician use to display detailed information (such as dns servers and mac addresses)?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!