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
ICE Princess25 [194]
3 years ago
15

Pascal's Triangle is a triangular array in which every number represents the

Computers and Technology
1 answer:
Viefleur [7K]3 years ago
6 0

Answer:

I am writing a JAVA program.

import java.util.Scanner;  // this class is used here to take input from user

import java.util.ArrayList;    // used to create dynamic arrays  

public class PascalTriangle{   // class to print nth line of pascal's triangle

/* function line() that takes the line index (line_no) as parameter and finds the nth line (find line at given index line_no) in the Pascal's Triangle */

   public static ArrayList<Integer> line(int line_no) {  

//declares ArrayList of integers

       ArrayList<Integer> current_line = new ArrayList<Integer>();  

       current_line.add(1);    // sets the element of every line to  1      

/* if conditions checks if the input n-th line is the first line which means it checks if the line to be returned is the 1st one */

       if (line_no == 0) {

       return current_line;  //returns the first line/row}  

/* the following statement produces the previous line by passing the index position (line_no-1) of that line as a parameter of line() method */    

       ArrayList<Integer> previous = line(line_no - 1);    

/* the loop has i variable which is initialized to 1 and this loop continues to execute until the value of i gets greater than or equal to the size of previous line */

       for (int i = 1; i < previous.size(); i++) {  //start of the loop

/* the following statement computes the current line based on the previous line of the Pascal triangle and this is a recursive part. This will compute the elements of the current line based on previous line and store these elements in present*/

           int present = previous.get(i - 1) + previous.get(i);  

//adds the elements computed by the above line to the current_line. this means it adds each element of present to current_line. For example if the n-th  line is 5 then it the elements at 6th row of pascals triangle are found and returned considering the topmost line the "0th" line */

           current_line.add(present); }  

       current_line.add(1);  

     return current_line; } //returns current line i.e. n-th line of pascal triangle  

   public static void main(String[] args)     {  //start of main() function body

      Scanner scan = new Scanner(System.in);  // create Scanner class object

/* prompts user to enter integer n as input to return the nth line of Pascal's triangle */

       System.out.print("Enter·line·of·Pascal's·Triangle·to·print: ");

       int n = scan.nextInt();    //scans and reads the input integer

// calls line function to return the n-th line of Pascal triangle

       ArrayList<Integer> array = line(n);  

       for (int i = 0; i < array.size(); i++) {  /* loop iterates through the array until the loop variable i gets equal to or exceeds the array size in order to display the elements of the n-th line of pascal triangle where n is integer input */

    System.out.print(array.get(i)+ "."); }    }  } //prints the elements of n-th line

/* get() method gets the elements of nth line and . is used to seperate each element with a dot. */

Explanation:

The program is well explained in the comments mentioned with each statement of the program. The program has a function line() that takes as argument the index line_no which is the nth line of Pascal's triangle whose elements are to be displayed. The program computes the line of the previous line number (index) first using recursion. After this the values of the current line is computed with the help of the previous one. This is iterated using a loop until the nth line. In the main() method user is prompted to enter integer n and then line() method is called by passing the n integer to the function to display the elements of this n-th line in pascal's triangle. loop is used to iterate through the entire array and get() method gets the elements of nth line of array and . is used to separate each element with a dot. The program and output is attached in a screenshot.

You might be interested in
Data driven processes: Select one: a. are heavily based on intuition b. rely heavily on the experience of the process owners c.
krek1111 [17]

Answer:

c. are based on statistical data, measurement and metrics

Explanation:

Data driven process are process that are not based on intuition but rather are based on data. This data serves as evidence to back a decision that is to be taken. It therefore means that, whatever decision that will be taken, such a decision will be based on the data presented.

6 0
2 years ago
attackers typically use ack scans to get past a firewall or other filtering device. how does the process of an ack scan work to
bogdanovich [222]

Attackers frequently use ACK scans to circumvent a firewall or other filtering tools. During a NULL scan, all packet flags are enabled. The most recent versions of Nessus Server and Client are compatible with Windows, Mac OS X, FreeBSD, and the vast majority of Linux variants.

<h3>What is ack scan ?</h3>
  • ACK scans are used to identify hosts or ports that have been blocked or are resistant to other types of scanning. An attacker uses TCP ACK segments to learn about firewall or ACL configuration.
  • Attackers probe our router or send unsolicited SYN, ACK, and FIN requests to specific UDP/TCP ports.
  • TCP ACK Scan sends an ACK message to the target port to determine whether or not it is filtered.
  • On unfiltered ports, a RST reply packet will be sent for both open and closed ports. Filtered ports will either generate no response or generate an ICMP reply packet with an unreachable destination.
  • The TCP ACK scanning technique attempts to determine whether a port is filtered by using packets with the ACK flag set.

To learn more about ask scan refer to:

brainly.com/question/13055134

#SPJ4

3 0
9 months ago
What does NVRAM stand for
Julli [10]
Non-Volatile Random Access Memory
7 0
3 years ago
Read 2 more answers
Assume that speed = 10 and miles = 5. What is the value of each of the
Assoli18 [71]

a. speed + 12 - miles * 2  = 10 + 12 - 5 * 2. With order of operations, we do the multiplication first so the equation is now 10 + 12 - 10 = 22 - 10 = 12

b. speed + miles * 3  = 10 + 5 * 3 and again, order of operations gives us 10 + 15 = 25

c. (speed + miles) * 3  = (10 + 5) * 3 = 15 * 3 = 45

d. speed + speed * miles + miles  = 10 + 10 * 5 + 5 = 10 + 50 + 5 = 60 + 5 = 65

e. (10 – speed) + miles / miles = (10 - 10) + 5 / 5 = 0 + 5 / 5 = 5 / 5 = 1

5 0
3 years ago
Some problems are better solved by a computer and some are better solved by humans.
aalyn [17]

Answer:

I say when u don't know the answer completly.

3 0
2 years ago
Other questions:
  • What is binary number
    11·1 answer
  • In addition to the four primary computer operations, today's computers almost always perform ____ functions.
    7·1 answer
  • What are some strategies that you can use when you debug a program?
    11·1 answer
  • Please answer this a due tomorrow!!!
    5·1 answer
  • Who is a software engineer
    8·2 answers
  • __________ contain(s) remnants of word processing documents, e-mails, Internet browsing activity, database entries, and almost a
    9·1 answer
  • Design 3 classes: Computer - Superclass
    11·1 answer
  • Write a program that repeatedly takes integers from the user as long as he
    7·1 answer
  • We have studied machine cycle in class. Suppose that each of the four modules of machine cycle is taking 2 seconds. If there are
    5·1 answer
  • The area that we can see just after windows is started is subject​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!