Which of the following methods calculates the nth Fibonacci number?
A) public static int method1(int n) {
if (n <= 2)
return 1;
else
return A(n - 1) ;
}
B) public static int method1(String str) {
if(str == null || str.equals("") )
return 0;
else
return 1 + method1(str.substring() ) ;
}
C) private static int method1(int Current, int Previous, int n) {
if (n == 1)
return Current;
else
return method1(Current + Previous, Current, n - 1) ;
}
D) public void method1(Object data) {
if (head == null)
head = new Node(data) ;
else
method1(head, data) ;
}
Correct Answer:
Verified
Q15: Classes that implement the Comparable interface must
Q16: Based on the algorithm below, which of
Q17: Which of the following is a recursive
Q18: A(n) _ data structure is one that
Q19: _ is an approach to implementing systematic
Q20: In terms of efficiency, the following method
Q22: The first language developed for artificial intelligence
Q23: Complete the following algorithm:
If n equals 0
N!
Q24: Complete the following algorithm for calculating gcd(m,n)
Q25: In a(n) _ search, we examine one
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents