Question
(Intro to java help?) Given the sequence, S2 = 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, Write a RECURSIVE method called sequence2
(Intro to java help?)
Given the sequence, S2 = 1, 2, 4, 5, 7, 8, 10, 11, 13, 14,
Write a RECURSIVE method called sequence2 that takes a single int parameter (n) and returns the int value of the nth element of the sequence S2. You will need to determine any base cases and a recursive case that describes the listed sequence.
Use the following code to test your answers to questions 3 and 4 the output should print the two sequences given (S & S2):
public class TestSequences {
public static void main(String[] args) {
for(int i = 0; i < 10; i++) {
System.out.print(sequence(i) + " "); // 2, 4, 6, 12, 22, 40, 74, 136, 250, 460
}
System.out.println();
for(int i = 0; i < 10; i++) {
System.out.print(sequence2(i) + " "); // 1, 2, 4, 5, 7, 8, 10, 11, 13, 14
}
}
// *** Your method for sequence here ***
// *** Your method for sequences2 here ***
} // end of TestSequences class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started