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.
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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images