Implement the following recursive methods (in java): // Recursively determines i
ID: 3754593 • Letter: I
Question
Implement the following recursive methods (in java):
// Recursively determines if the substring of num with starting index i and ending index j is a palindrome
public static boolean recursiveIsPalindrome(String num, int i, int j)
{
// TO DO (A)
}
// Recursively calculates the nth fibonacci number
public static long recursiveFibonacci(int n)
{
// TO DO (B)
}
// Recursively calculates the GCD of a and b
public static int recursiveGCD(int a, int b)
{
// TO DO (C)
}
// Recursively calculates an
public static double recursivePowInt(double a, int n)
{
// TO DO (D)
}
Explanation / Answer
public class RecursiveMethods { // Recursively determines if the substring of num with starting index i and ending index j is a palindrome public static boolean recursiveIsPalindrome(String num, int i, int j) { if(i >= j) { return true; } else { return num.charAt(i) == num.charAt(j) && recursiveIsPalindrome(num, i+1, j-1); } } // Recursively calculates the nth fibonacci number public static long recursiveFibonacci(int n) { if(n b) return recursiveGCD(a-b, b); else return recursiveGCD(a, b-a); } // Recursively calculates an public static double recursivePowInt(double a, int n) { if(n == 0) { return 1; } else { return a * recursivePowInt(a, n-1); } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.