Calculate the n-th line of pascal triangle

Assignment Help Basic Computer Science
Reference no: EM131916460

Implement a class to recursively calculate the n-th line of 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) {

       return new int[]{0};

   }

}

Reference no: EM131916460

Questions Cloud

Apex programming language by salesforce : In Apex programming language by Salesforce (or java), when declaring a list, why is it necessary to say the data type and list name twice?
What advantage does education offer : How do the two approaches differ in the ability to solve sanitation problems? What advantage does education offer? How does the policy shift affect our ability?
The firm cost of capital and risk free rate : If the firm's cost of capital is 10 percent, and the risk free rate is 6 percent should the investment be made?
Create a web query for each stock : Create a Web Query for each stock to one of the resources you found from Module 2. The web queries should be created in a new worksheet or worksheets.
Calculate the n-th line of pascal triangle : Implement a class to recursively calculate the n-th line of Pascal's Triangle:
The flotation cost as percentage of funds raised : What was the flotation cost as a percentage of funds raised? What are the total indirect costs?
Stages of system development life cycle : Explain the role of the systems analyst during each of the 5 phase of the Stages of system development Life cycle:
Briefly define the term waterfall model : A. Briefly define the term Waterfall model? And list the phases of the development process in order they are done?
Preparation of an investment portfolio proposal document : FIN3CSF INVESTMENT PORTFOLIO CONSTRUCTION- This case study requires the preparation of an investment portfolio proposal document to be provided to the client

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Results of the internal environmental scan

Examine the results of the internal environmental scan findings in the analysis. Examine the results of the external environmental scan findings in the analysis.

  Identify the main entities of fast cabs

Using your answers (a) to (e) represent the data requirements of the Fast Cabs as an enhanced ER (EER) model. (Hint: Use optional Step 1.6 of the methodology to identify private clients (subclass) and business clients (subclass) as being special t..

  Routing protocols operate at the network layer

Routing protocols operate at the Network Layer

  Security problems and damage systems

What is a hacker? What are some of the ways hackers can create security problems and damage systems?

  Signing of the representation agreement

Assume further that Goode later signs a representation agreement. Would either meeting or the signing of the representation agreement adversely affect.

  Authentication and identification could be considered

Also share if you feel the requested authentication and identification could be considered "reliable". Can you explain?

  Which of these probability assignments are legitimate

The store is required to reveal (in the fine print) the distribution of discounts available. Which of these probability assignments are legitimate?

  What would you expect to be the limiting value of c

(a) What is the average yearly rate of change of carbon-14 during the first 5000 years? (Round your answer to six decimal places.) g/yr (b) How many grams of carbon-14 would you expect to find remaining after 2005 years? (Round your answer to two d..

  Find two different cloud backup providers

Use a search engine to find two different cloud backup providers. Compare their pricing plans, storage offered, file types backed up, security features.

  Discussion of the lightness algorithm

We ignore color interreflections in our surface color model. Do an experiment to get some idea of the size of color shifts possible from color interreflections.

  Multi-layered security plan

You are a network security specialist at Richman Investments, a mid-level financial investment and consulting firm. The Richman corporate headquarters is located in Phoenix, Arizona. Currently, there are eight branch offices in:  Atlanta, Georgia ..

  Threat and risk of location privacy-security

Explanation of Threat and Risk. How to Control of Threats and Risks?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd