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
Select the correct answer.<br><br> Which statement is true with respect to Java?
NARA [144]

Answer:

where are the options ..... to select

7 0
3 years ago
The Green Revolution innovations in agriculture based on a package of inputs including all of the following except?
timofeeve [1]

Answer:

natural fertilizers such as compost, green maure, animal manure

Explanation:

The Green Revolution was a movement whose main goal was to drastically increase the agriculture yields in every location. They accomplished this by using hybrid seeds, irrigation, chemical fertilizers, pesticides, fossil fuels, farm machinery, and high-tech growing and processing systems, all of which greatly contributed towards this goal. Therefore the one thing that was not part of the Green Revolution's innovations was natural fertilizers such as compost, green maure, animal manure, mainly due to the fact that these were the traditional use that would lead to the same agriculture yields.

6 0
3 years ago
An internet service provider has three different subscription packages for its customers.  Package A: For $9.95 per month 10 ho
tiny-mole [99]

Answer:

C++.

Explanation:

int main() {

   const float package_A = 9.95;

   const float package_B = 14.95;

   const float package_C = 19.95;

   const int package_A_extra = 2;

   const float package_B = 1;

/////////////////////////////////////////////////////////////////////////////

   int user_package_choice;

   int hours_used;

   cout<<"Your package? Enter option number,"<<endl;

   cout<<"1. Package A"<<endl<<"2. Package B"<<"3. Package C";

   cout<<endl;

   cin<<user_package;

   cout<<endl;

   cout<<"Hours used?: ";

   cin<<hours_used;

/////////////////////////////////////////////////////////////////////////////

   cout<<endl;

   float total_amount;

   if (user_package_choice == 1) {

       total_amount = package_A + ((hours_used - 10) * package_A_extra));

       if (total_amount - (package_B + ((hours_used - 20) * package_B_extra)) > 0)

          cout<<"If you had opted for Package B, you would have saved $"<<total_amount - (package_B + (hours_used * package_B_extra))<<endl;

       if (total_amount - package_C > 0)

           cout<<"If you had opted for Package C, you would have saved $"<<total_amount - package_C;

   }

   else if (user_package_choice == 2) {

       total_amount = package_B + ((hours_used - 20) * package_B_extra);

        if (total_amount - package_C > 0)

           cout<<"If you had opted for Package C, you would have saved $"<<total_amount - package_C;

   }

   else {

       total_amount = package_C;

   }

   return 0;

}

4 0
4 years ago
Assuming a 32bit processor If I have a double pointer defined as dPtr and I add 1 to it. How many bytes are added to the address
Anni [7]

Answer:

Theoretically one could design an architecture that would address 16 GB of memory with 32-bits of unique addresses.

Explanation:

4 0
2 years ago
Please help me please i really need helpp so i can pass
Alchen [17]

Answer:

Piezoelectric gauge is used to convert charge into measureable electric signal.

Universal serial bus interface allows a computer and flash drive to exchange information.

Analytical balance is used to measure mass

Ultrasonic flow sensors measure the seed of water using ultrasonic waves.

Explanation:

Analytical balance is used to measure mass. An analytical balance is a device that can measure the mass of an object  accurately. It can also measure very small amount of mass with a range between 0.1mg - 0.01mg.

Universal serial bus interface allows a computer and flash drive to exchange information. A Universal Serial Bus (USB) is an interface that allows communication between peripheral devices and a computer. It connects peripheral devices such as mouse, keyboards, printers, scanners, external hard drives and flash drives with the computer.

Piezoelectric gauge is used to convert charge into measureable electric signal. A piezoelectric gauge has a piezoelectric sensor that uses piezoelectric effect to measure changes in pressure, temperature, force and convert these changes into electrical charge.

Ultrasonic flow sensors measure the speed of flowing liquid using ultrasonic waves. It uses sound waves to determine the speed of the liquid.

7 0
3 years ago
Other questions:
  • HELP ASAP!!!! PLEASE !!! What information does the Media Access Control (MAC) on a network card provide?
    9·2 answers
  • Technlogies are having a negative impact on business true or false
    7·1 answer
  • Consider a class called Rocket that has a private instance variable called Engine. You are writing a "getter" for the Engine. Us
    7·1 answer
  • Write a program that prompts the user to input a number. The program should then output the number and a message saying whether
    10·1 answer
  • PLZ HELPPPPPPPPPPPPPPPPPPPP
    9·1 answer
  • 2. Driving above the posted speed limit is _
    13·2 answers
  • Describe a hybird electrical vehical
    12·1 answer
  • Un polímero sintético es renovable o no renovable
    11·1 answer
  • 1. Microsoft Excel, MS Excel, or simply Excel is a______application by Microsoft Corporation. 2. Excel allows you to organize an
    13·1 answer
  • While storms could be a cause, power______ are more likely to be caused by disturbances from high-demand equipment in a home or
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!