subject

The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the previous two, for example: 0, 1, 1, 2, 3, 5, 8, 13. Complete the fibonacci() method, which takes in an index, n, and returns the nth value in the sequence. Any negative index values should return -1. Ex: If the input is: 7
the out put is :fibonacci(7) is 13
Note: Use recursion and DO NOT use any loops. // is this mean i don't have to use loops? for (int i = 1; i<= n; ++i)
import java. util. Scanner;
public class LabProgram {
public static int fibonacci(int n) {
/* Type your code here. */
public static void main(String[] args) {
Scanner scnr = new Scanner(System. in);
int startNum;
System. out. println("Enter your number: ");
startNum = scnr. nextInt();
System. out. println("fibonnaci(" + startNum + ") is " + fibonacci(startNum));
}
}

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 17:00, evanwall91
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
image
Computers and Technology, 24.06.2019 13:00, toshahoskins0098
What are some websites that you can read manga (ex: manga rock)
Answers: 1
image
Computers and Technology, 24.06.2019 17:40, finedock
Anewly established internet company with 40 employees needs your advice. they are looking for a collaboration tool and have narrowed their choices to gotomeeting, webex, and my web conferences. after reading the information presented in this chapter and other sources, prepare a two- page document ( double spaced) that includes two advantages and two disadvantages of each tool. which one is your final recommendation? why did you choose that tool over the other two?
Answers: 3
image
Computers and Technology, 25.06.2019 08:30, llamaSmartz
Ais a modeling tool used in structured systems analysis and design (ssad) analysis model that break down a complex process into simpler, more manageable, and more understandable subprocesses
Answers: 1
You know the right answer?
The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the pr...

Questions in other subjects: