# Recursive Functions Project Help Using Java

This is a Definition and writing of Recursive Functions Project Help completed by a java homework help specialist from our platform. It shows various steps in defining recursive functions given the type signature. It also shows how to test the respective functions for correctness. ## Defining Various Sequences Given The Type Signature

• Deﬁne factorial with the following type signature:
public static double factorial ( double n)
It’s speciﬁcation is given above.
• Deﬁne ﬁbonacci with the following type signature:
public static double fibonacci( double n)
F(0) = 0
F(1) = 1
F(n) = F(n−1) + F(n−2)
##### Defining Unnamed Sequences Given The Type Signatures
• Deﬁne an unnamed sequence with the following type signature:
public static double sequence1 ( double n)
F(0) = 2
F(1) = 2 F(n) = 2∗F(n−1)−1
• Deﬁne an unnamed sequence with the following type signature:
public static double sequence2 ( double n)
F(0) = 5
F(1) = 5
F(n) = 3∗F(n−1)
##### Defining Named Sequences Given Type Signatures
• Deﬁne Hofstadter’s Q-sequence with the following type signature:
public static double hofsQ( double n)
F(0) = 1
F(1) = 1
F(2) = 1
F(n) = F(n−F(n−1)) + F(n−F(n−2))
• Deﬁne the tetration operation with the following type signature where a is being taken to the tetration power of n:
public static double tetration( double a , double n)
F(a,0) = 1
F(a,n) = aF(a,n−1)
Remember that ˆ in Java does not perform exponentiation but rather XOR. Use Math.pow to perform exponentiation.
• Deﬁne a mathematical sequence of your choice. The only speciﬁcation that it must follow is that it must return a double and take at least one double as an argument.
##### Solution
public class Main {
public static void main(String[] args) {
System.out.println("factorial(2) = " + factorial(2));
System.out.println("factorial(10) = " + factorial(10));
System.out.println("fibonacci(2) = " + fibonacci(2));
System.out.println("fibonacci(10) = " + fibonacci(10));
System.out.println("sequence1(2) = " + sequence1(2));
System.out.println("sequence1(10) = " + sequence1(10));
System.out.println("sequence2(2) = " + sequence2(2));
System.out.println("sequence2(10) = " + sequence2(10));
System.out.println("hofsQ(2) = " + hofsQ(2));
System.out.println("hofsQ(10) = " + hofsQ(10));
System.out.println("tetration(2, 3) = " + tetration(2, 3));
System.out.println("tetration(3, 2) = " + tetration(3, 2));
System.out.println("tetration(3, 3) = " + tetration(3, 3));
}
public static double factorial(double n) {
if (n >= 1)
return n * factorial(n - 1);
else
return 1;
}
public static double fibonacci(double n) {
if (n == 0) {
return 0;
}
if (n == 1 || n == 2) {
return 1;
}
return fibonacci(n - 2) + fibonacci(n - 1);
}
public static double sequence1(double n) {
if (n == 0 || n == 1)
return 2;
return 2 * sequence1(n - 1) - 1;
}
public static double sequence2(double n) {
if (n == 0 || n == 1)
return 5;
return 3 * sequence2(n - 1);
}
public static double hofsQ(double n) {
if (n == 0 || n == 1 || n == 2)
return 1;
return hofsQ(n - hofsQ(n - 1)) + hofsQ(n - hofsQ(n - 2));
}
public static double tetration(double a, double n) {
if (n == 0)
return 1;
return Math.pow(a, tetration(a, n - 1));
}
// your chosen math sequence goes here
}
Testing the Functions
Here is some output from these functions that you can use to make sure your functions are correct:
fibonacci(2) = 1.0
fibonacci(10) = 55.0
sequence1(2) = 3.0
sequence1(10) = 513.0
sequence2(2) = 15.0
sequence2(10) = 98415.0
hofsQ(2) = 1.0
hofsQ(10) = 6.0
tetration(2,3) = 16.0
tetration(3,2) = 27.0
tetration(3,3) = 7.625597484987E12 Related Blogs

Java tutors in the USAJava is a computing language designed for the development of desktop and mobile applications, embedded systems, and the processing of big data. Introduced in 1995, Java is so much like C and C + + but easier to use because it enforces the object-oriented programming model. One ...

2020-07-25

Are You Troubled with Your Java Programming Homework?Java programming language was derived from C but is more flexible and compatible with multiple platforms. Java’s true power lies within people’s ability to manipulate the objects and variables within a program, which is why it is considered an obj...

2020-08-12

Why You May Seriously Need Help With Java Programming Homework?How well are you conversant with Java programming? Given Java homework, can you handle it correctly for impressive results? Well, if you can not, there is a need to seek help with the Java programming homework. Also, even after get...

2020-08-12