Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Coding in java 1. Write a method that uses recursion to raise a number to a powe

ID: 644141 • Letter: C

Question

Coding in java

1. Write a method that uses recursion to raise a number to a power. The method should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer. Demonstrate the method in a program.

2.

Ackermann's function is a recursive mathematical algorithm that can be used to test how

well a computer performs recursion. Write a method ackennann(m, n), which solves Acker-

mann's function. Use the following logic in your method:

If m = 0 then return n + I

If n = 0 then return ackermann(m -1, 1)

Otherwise, return ackermann(m

Explanation / Answer

1.ackerman(int a, int b){

int x,y,z;

x=a;

y=b;

z=x^y;

return z;

}

2.

ackermann(0,0), would return the value 0,

ackermann(0,1), return the value 0,

ackermann(1,1) return the value 1,

ackermann(1,3) return the error, because l is not an integer,

ackermann(2,2) return the value 4,

ackermann(3,2) return the value 9.