x^{0} = 1 x^{y} = x*x^{y-1} for all y > 1File Power.java contains a main program that reads in integers base and exp and calls method power to compute base^{exp}. Fill in the code for power to make it a recursive method to do the power computation.
Print Power.java.
fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) + fib(n-2) n>1For example, the first eight elements of the sequence are 0,1,1,2,3,5,8,13.
Because the Fibonacci sequence is defined recursively, it is natural to write a recursive method to determine the nth number in the sequence. File Fib.java contains the skeleton for a program that reads an integer n from and computes and prints the n^{th} Fibonacci number. Save this file to your directory. Following the specification above, fill in the code for method fib so that it recursively computes and returns the nth number in the sequence.
Print Fib.java.
If s contains any characters (i.e., is not the empty string)
File Backwards.java contains a program that prompts the user for a string, then calls method printBackwards to print the string backwards. Save this file to your directory and fill in the code for printBackwards using the recursive strategy outlined above. Recall that for a String s in Java,
Print Backwards.java.
public static int gcd (int num1, int num2) { int c; while (num2!=0) { c=num2; num2=num1%num2; num1=c; } return num1; }Study this code and perform a couple of hand traces to figure out how it works. Create a class called DivisorCalc that implements a recursive version of the gcd method and a driver program to test your implementation. Remember the steps in recursive method design.
What is the base case?
What is the recursive step?
Here is an example for converting 30_{10} to base 4:
quotient remainder -------- --------- 30/4 = 7 2 7/4 = 1 3 1/4 = 0 1The answer is read bottom to top in the remainder column, so 30_{10} = 132_{4}.
Think about how this is recursive in nature: If you want to convert x (30 in our example) to base b (4 in our example), the rightmost digit is the remainder x % b. To get the rest of the digits, you perform the same process on what is left; that is, you convert the quotient x / b to base b. If x / b is 0, there is no rest; x is a single base b digit and that digit is x % b (which also is just x).
The file BaseConversion.java contains the shell of a method convert to do the base conversion and a main method to test the conversion. Note that the convert method returns a string representing the base b number. This means that in the base case, when the remainder is what is to be returned, it must be converted to a String object by concatenating it with a null string. Similarly, in the recursive case the result of the recursive call will be concatenated with the remainder.
Fill in the code for convert and the call in the main method. Here is some data to test your program on:
Print BaseConversion.java.