Question: JAVA Task 1 Write a recursive function that takes a positive integer n as input and returns the value of 13+23+33++n3. You are not allowed

JAVA

JAVA Task 1 Write a recursive function that takes a positive integern as input and returns the value of 13+23+33++n3. You are not

Task 1 Write a recursive function that takes a positive integer n as input and returns the value of 13+23+33++n3. You are not allowed to use a loop inside the method. Task 2 Write a function that gives change, i.e. it takes an amount as argument, and it prints out Ps,Ns,D 's, and Q s - one for each penny ( 1 cent), nickle (5 cent), dime (10 cent) and quarter ( 25 cent) it gives out. Ex: If Amount is 33 , it would print out: QNPPP Your function should be recursive, and here's some simple rules to help you (let A be the amount you need change for): 1) If A is 0 , don't give anything! 2) If A>0, give out one of the largest denomination not exceeding A, then make change for the remaining amount. Task 3 In the previous task, the output was ordered from the highest value coin to lowest value coin. Change the above function to display from lowest value coin to highest value coin. Ex: If Amount is 33 , it would print out: PPPNQ Task 4 In the lecture, we implemented expon which raises x to the nth power. It took advantage of the fact that xn=x(x(n1)) Using recursion (no loops) implement the method fastExpon which raises x to the nth power. It will take advantage of the fact that if n is even, then: xn=(xn/2)2 to greatly reduce the number of of recursive calls and multiplications that will need to be done to compute the answer. (We're using to indicate exponentiation in the above formula.) You may assume x and n will both be nonnegative

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!