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
How long does it take to wash 12 t-shirts in the quickest way?​
Alex_Xolod [135]

Answer:

Please let me know also

3 0
4 years ago
Read 2 more answers
CAN SOMEONE PLEASE HELP ME WITH THIS PLEASE ?!!!!!!!!
kherson [118]
Get feedback about your product from the restaurant
7 0
3 years ago
A computer may keep freezing if it's software is up-to-date? <br> True <br> False
tester [92]

Answer:

false

Explanation:

6 0
4 years ago
__________ often causes overactive eye movement.
shepuryov [24]
The answer is ; D , xanax
3 0
3 years ago
Read 2 more answers
Which of the instances below is an example of a Trojan horse? Question 2 options: a) An attachment in an email that is really a
sergij07 [2.7K]

Game-theif Trojans is the malware that makes a backdoor into your email account by which you are playing a game or has downloaded it and thus by this all information of user is exposed.

So option D is the answer.

Option A cannot be answer because Trojan does not use files for its purpose.

Option B cannot be a good option because Trojan works in online could.

Option C cannot be a option because Trojan does not need executable to attack your account.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Describe the difference between gui and cli​
    9·1 answer
  • You can change the color of the value of a cell or the background
    14·2 answers
  • Can you please help me at question two
    13·1 answer
  • Alessandro wants to use his desktop computer to video chat with his mother. What hardware does he need to accomplish this?
    9·1 answer
  • We can include following item(s) during configuration itemidentification:
    10·1 answer
  • An interrupt priority scheme can be used to ____. allow the most urgent work to be finished first make it possible for high-prio
    14·1 answer
  • Members of the sales team use laptops to connect to the company network. While traveling, they connect their laptops to the inte
    15·1 answer
  • Need to know? Anyone feel like helping me not fail
    13·1 answer
  • Examples of the many different ways an app can be used are called use
    6·2 answers
  • On what aspect of digital media do people often focus on at the expense of the important supporting roles?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!