Project Recursive Auxiliary Math Create a project named Recursive Auxiliary Math
ID: 3790429 • Letter: P
Question
Project Recursive Auxiliary Math Create a project named Recursive Auxiliary Math that illustrates use of recursion. This project will have the following: A class named Recursive Auxiliary Math that has the following static methods public static Boolean recess Palindrome (String nun, int i, int j) public static long refinance (int n) public static int recGCD(int a, int b) public static double recPowInt(double a, int n) 2) The main class, named Recursive Auxiliary Math Demo, with one method: Enter three integers whose GCD is to be found rightarrow 120 90 -75 Enter an integer to find the nth Fibonacci number rightarrow 30 Enter the base and exponent, an integer, of a power rightarrow -4.5 -3 Enter two positive integers 1 and j where iExplanation / Answer
import java.util.*;
import java.io.*;
class RecursiveAuxiliaryMath{
public static boolean recIsPalidrome(String num, int i, int j){
if(i>=j){
return true;
}
else{
if(num.charAt(i)!=num.charAt(j)){
return false;
}
else{
recIsPalidrome(num,i+1,j-1);
}
}
return true;
}
public static long recFebonacci(int n){
if(n==0){
return 0;
}
else if(n==1){
return 1;
}
else{
return recFebonacci(n-1)+recFebonacci(n-2);
}
}
public static int recGCD(int a, int b){
if(b!=0){
return recGCD(b,b%a);
}
else{
return a;
}
}
public static double recPowInt(double a, int n){
if(n==1){
return a;
}
else{
return recPowInt(a*a,n-1);
}
}
}
public class RecursiveAuxiliaryMathDemo{
public static void main(String[] args){
int a,b,c,n,p,i,j;
double x;
Scanner reader = new Scanner(System.in); // Reading from System.in
//gcd of three numbers
System.out.println("Enter three integers whose GCD is to be found: ");
a = reader.nextInt();
b = reader.nextInt();
c = reader.nextInt();
int h = recGCD(a,b);
h = recGCD(h,c);
// System.out.println("gcd ("+a+","+b+","+c+") is "+h);
//nth fibonacci number
System.out.println("Enter an integer n to find the nth fibonacci number: ");
n = reader.nextInt();
m = recFebonacci(n);
// System.out.println("fibo("+n+") "+m);
//x to power p
System.out.println("Enter the base and exponent, an integer, of a power: ");
x = reader.nextInt();
p = reader.nextInt();
q = recPowInt(x,p);
System.out.println(q);
System.out.println("Enter the positive integers i and j where i < j: ");
i = reader.nextInt();
j = reader.nextInt();
int count=0;
for(int k=i; k<=j; k++){
if(recIsPalidrome(k)){
count++;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.