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
Rama09 [41]
3 years ago
12

I need to create a function that returns Pascal's Triangle with n rows, where n is an int argument.

Computers and Technology
1 answer:
Ede4ka [16]3 years ago
6 0

A function that returns Pascal's Triangle with n rows:

//import necessary headers

public class Pascal_Triangle {

   // calculate factorial  

   static int factorial(int n)

   {

       int fact = 1;

       int i;

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

       {

           fact*=i;

       }

       return i;

   }

   // Actual code to display the //pascal triangle

   static void display(int n)  

   {

       int i;

       int line;

       for(line=1;line<=n;line++)

       {

           for(i=0;i<=line;i++)

           {

               System.out.print((factorial(line)/factorial(line-i) * factorial(i)) + " ");

           }

           System.out.println();

       }

   }

   // To read user input

   public static void main(String[] args){  

       BufferedReader breader=new BufferedReader(new InputStreamReader(System.in));

       int n;

       System.out.println("Enter the size for creating Pascal triangle");

       try {

           n = Integer.parseInt(breader.readLine());

       }

       catch(Exception e){

           System.out.println("Please enter a valid Input");

           return;

       }

       System.out.println("The Pascal's Triangle is");

       display(n);

   }

}

You might be interested in
What is a symptom of a failing power supply? The display has only a blinking cursor. The computer displays a POST error code. Th
Mariulka [41]

Answer:

A sympton of a failing power supply is The computer sometimes does not turn on.

Explanation:

All right, the power supply is the terminal that receives electric current to process it and distribute it to the different parts of the hardware that compose the computer. When it fails, the current is not distributed and doesn't reach the different pieces of hardware. Therefore, option D) is the correct one. Another error that could be related is the malfunction of fans but it could be related to wires more than the power itself.

7 0
3 years ago
How to scan a screenshot on Brainly?
yulyashka [42]

Answer:

You go to the option that says "snap to solve" an that's it

5 0
2 years ago
Read 2 more answers
How do you enter the command prompt on Chromebook
Step2247 [10]

1) Go through the standard Chrome OS login screen (you'll need to setup a network, etc) and get to the web browser. It's OK if you login as guest.

2) Press [ Ctrl ] [ Alt ] [ T ] to get the crosh shell.

3) Use the shell command to get the shell prompt.

3 0
3 years ago
How did<br> technological artifacts evolved over time?
adell [148]
With helping us communicate with each other and around the world with the internet and other different types of things like,Tesla’s,phones,touch screen IPads,even having a built in TV plane
3 0
2 years ago
What is the most important external issue when using social media in emergency management?
DerKrebs [107]
Th e most important external issue when using social media in emergency management is the disaster response. Disseminating information through social media is very effective especially when there are calamities and a disaster respond from both private and public sector is very urgent.
8 0
3 years ago
Other questions:
  • Please help with this
    5·2 answers
  • What are the problems with security when working on a Web Page?
    13·2 answers
  • You can join tables by using a condition in the ____ clause.​
    7·1 answer
  • This diagram shows a number of computing devices connected to the Internet with each line representing a direct connection.
    11·1 answer
  • The___provides access to the internet; may also be internal
    11·1 answer
  • (PYTHON HOMEWORK)Given the following code snippet, which statement tests to see if all three sets are equal?:
    11·1 answer
  • Read the following example cover letter: To Ms. March: I was excited to see your opening for a customer support specialist with
    13·1 answer
  • My serious question that needs answering pronto!!!
    11·1 answer
  • The Python language uses a compiler which is a program that both translates and executes the instructions in a high-level langua
    15·1 answer
  • Why do many experts recommand longer time horizonal if you are doing high risk investment
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!