SlideShare une entreprise Scribd logo
1  sur  1
Télécharger pour lire hors ligne
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:
the output is:
Note: Use recursion and DO NOT use any loops.
this is the code:
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;
startNum = scnr.nextInt();
System.out.println("fibonacci(" + startNum + ") is " + fibonacci(startNum));
}
}

Contenu connexe

Plus de sgambikaproducts

The following information applies to the questions displayed below] .pdf
The following information applies to the questions displayed below] .pdfThe following information applies to the questions displayed below] .pdf
The following information applies to the questions displayed below] .pdfsgambikaproducts
 
The following income statement was drawn from the records of Munoz, .pdf
The following income statement was drawn from the records of Munoz, .pdfThe following income statement was drawn from the records of Munoz, .pdf
The following income statement was drawn from the records of Munoz, .pdfsgambikaproducts
 
The following excerpts have been taking from a patient � Maisie Wils.pdf
The following excerpts have been taking from a patient � Maisie Wils.pdfThe following excerpts have been taking from a patient � Maisie Wils.pdf
The following excerpts have been taking from a patient � Maisie Wils.pdfsgambikaproducts
 
The following events occurred in the recent past in Canada� The w.pdf
The following events occurred in the recent past in Canada� The w.pdfThe following events occurred in the recent past in Canada� The w.pdf
The following events occurred in the recent past in Canada� The w.pdfsgambikaproducts
 
The following diagram shows the chromosomes with their associated ge.pdf
The following diagram shows the chromosomes with their associated ge.pdfThe following diagram shows the chromosomes with their associated ge.pdf
The following diagram shows the chromosomes with their associated ge.pdfsgambikaproducts
 
The firm is currently an all-equity firm with assets worth $250 mill.pdf
The firm is currently an all-equity firm with assets worth $250 mill.pdfThe firm is currently an all-equity firm with assets worth $250 mill.pdf
The firm is currently an all-equity firm with assets worth $250 mill.pdfsgambikaproducts
 
The financial records of Vaughn Inc. were destroyed by fire at the e.pdf
The financial records of Vaughn Inc. were destroyed by fire at the e.pdfThe financial records of Vaughn Inc. were destroyed by fire at the e.pdf
The financial records of Vaughn Inc. were destroyed by fire at the e.pdfsgambikaproducts
 
The figure above shows graphs of oxygen consumption and of ATP synth.pdf
The figure above shows graphs of oxygen consumption and of ATP synth.pdfThe figure above shows graphs of oxygen consumption and of ATP synth.pdf
The figure above shows graphs of oxygen consumption and of ATP synth.pdfsgambikaproducts
 
The dirname utility treats its argument as a pathname and wri.pdf
The dirname utility treats its argument as a pathname and wri.pdfThe dirname utility treats its argument as a pathname and wri.pdf
The dirname utility treats its argument as a pathname and wri.pdfsgambikaproducts
 
The Federal Register is best described by which of the following sta.pdf
The Federal Register is best described by which of the following sta.pdfThe Federal Register is best described by which of the following sta.pdf
The Federal Register is best described by which of the following sta.pdfsgambikaproducts
 
The Federal Information Security Modernization Act (FISMA) was desig.pdf
The Federal Information Security Modernization Act (FISMA) was desig.pdfThe Federal Information Security Modernization Act (FISMA) was desig.pdf
The Federal Information Security Modernization Act (FISMA) was desig.pdfsgambikaproducts
 
The FASB requires that a statement showing the relationship of funct.pdf
The FASB requires that a statement showing the relationship of funct.pdfThe FASB requires that a statement showing the relationship of funct.pdf
The FASB requires that a statement showing the relationship of funct.pdfsgambikaproducts
 
The event that causes the release of high levels of estrogen release.pdf
The event that causes the release of high levels of estrogen release.pdfThe event that causes the release of high levels of estrogen release.pdf
The event that causes the release of high levels of estrogen release.pdfsgambikaproducts
 
The economic model of Human Capital Investment assumes that individu.pdf
The economic model of Human Capital Investment assumes that individu.pdfThe economic model of Human Capital Investment assumes that individu.pdf
The economic model of Human Capital Investment assumes that individu.pdfsgambikaproducts
 
The data contains 28 under ned features which de ne the type of tran.pdf
The data contains 28 under ned features which de ne the type of tran.pdfThe data contains 28 under ned features which de ne the type of tran.pdf
The data contains 28 under ned features which de ne the type of tran.pdfsgambikaproducts
 
The diagram below displays a concentration gradient at 4 differe.pdf
The diagram below displays a concentration gradient at 4 differe.pdfThe diagram below displays a concentration gradient at 4 differe.pdf
The diagram below displays a concentration gradient at 4 differe.pdfsgambikaproducts
 
The engineers for the Ariane 5 followed the principle of redundant .pdf
The engineers for the Ariane 5 followed the principle of redundant .pdfThe engineers for the Ariane 5 followed the principle of redundant .pdf
The engineers for the Ariane 5 followed the principle of redundant .pdfsgambikaproducts
 
The emergence of cryptocurrencies, stablecoins, and other decentrali.pdf
The emergence of cryptocurrencies, stablecoins, and other decentrali.pdfThe emergence of cryptocurrencies, stablecoins, and other decentrali.pdf
The emergence of cryptocurrencies, stablecoins, and other decentrali.pdfsgambikaproducts
 
The Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdf
The Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdfThe Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdf
The Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdfsgambikaproducts
 
The District of Columbia has 345 ICU beds under normal conditions, a.pdf
The District of Columbia has 345 ICU beds under normal conditions, a.pdfThe District of Columbia has 345 ICU beds under normal conditions, a.pdf
The District of Columbia has 345 ICU beds under normal conditions, a.pdfsgambikaproducts
 

Plus de sgambikaproducts (20)

The following information applies to the questions displayed below] .pdf
The following information applies to the questions displayed below] .pdfThe following information applies to the questions displayed below] .pdf
The following information applies to the questions displayed below] .pdf
 
The following income statement was drawn from the records of Munoz, .pdf
The following income statement was drawn from the records of Munoz, .pdfThe following income statement was drawn from the records of Munoz, .pdf
The following income statement was drawn from the records of Munoz, .pdf
 
The following excerpts have been taking from a patient � Maisie Wils.pdf
The following excerpts have been taking from a patient � Maisie Wils.pdfThe following excerpts have been taking from a patient � Maisie Wils.pdf
The following excerpts have been taking from a patient � Maisie Wils.pdf
 
The following events occurred in the recent past in Canada� The w.pdf
The following events occurred in the recent past in Canada� The w.pdfThe following events occurred in the recent past in Canada� The w.pdf
The following events occurred in the recent past in Canada� The w.pdf
 
The following diagram shows the chromosomes with their associated ge.pdf
The following diagram shows the chromosomes with their associated ge.pdfThe following diagram shows the chromosomes with their associated ge.pdf
The following diagram shows the chromosomes with their associated ge.pdf
 
The firm is currently an all-equity firm with assets worth $250 mill.pdf
The firm is currently an all-equity firm with assets worth $250 mill.pdfThe firm is currently an all-equity firm with assets worth $250 mill.pdf
The firm is currently an all-equity firm with assets worth $250 mill.pdf
 
The financial records of Vaughn Inc. were destroyed by fire at the e.pdf
The financial records of Vaughn Inc. were destroyed by fire at the e.pdfThe financial records of Vaughn Inc. were destroyed by fire at the e.pdf
The financial records of Vaughn Inc. were destroyed by fire at the e.pdf
 
The figure above shows graphs of oxygen consumption and of ATP synth.pdf
The figure above shows graphs of oxygen consumption and of ATP synth.pdfThe figure above shows graphs of oxygen consumption and of ATP synth.pdf
The figure above shows graphs of oxygen consumption and of ATP synth.pdf
 
The dirname utility treats its argument as a pathname and wri.pdf
The dirname utility treats its argument as a pathname and wri.pdfThe dirname utility treats its argument as a pathname and wri.pdf
The dirname utility treats its argument as a pathname and wri.pdf
 
The Federal Register is best described by which of the following sta.pdf
The Federal Register is best described by which of the following sta.pdfThe Federal Register is best described by which of the following sta.pdf
The Federal Register is best described by which of the following sta.pdf
 
The Federal Information Security Modernization Act (FISMA) was desig.pdf
The Federal Information Security Modernization Act (FISMA) was desig.pdfThe Federal Information Security Modernization Act (FISMA) was desig.pdf
The Federal Information Security Modernization Act (FISMA) was desig.pdf
 
The FASB requires that a statement showing the relationship of funct.pdf
The FASB requires that a statement showing the relationship of funct.pdfThe FASB requires that a statement showing the relationship of funct.pdf
The FASB requires that a statement showing the relationship of funct.pdf
 
The event that causes the release of high levels of estrogen release.pdf
The event that causes the release of high levels of estrogen release.pdfThe event that causes the release of high levels of estrogen release.pdf
The event that causes the release of high levels of estrogen release.pdf
 
The economic model of Human Capital Investment assumes that individu.pdf
The economic model of Human Capital Investment assumes that individu.pdfThe economic model of Human Capital Investment assumes that individu.pdf
The economic model of Human Capital Investment assumes that individu.pdf
 
The data contains 28 under ned features which de ne the type of tran.pdf
The data contains 28 under ned features which de ne the type of tran.pdfThe data contains 28 under ned features which de ne the type of tran.pdf
The data contains 28 under ned features which de ne the type of tran.pdf
 
The diagram below displays a concentration gradient at 4 differe.pdf
The diagram below displays a concentration gradient at 4 differe.pdfThe diagram below displays a concentration gradient at 4 differe.pdf
The diagram below displays a concentration gradient at 4 differe.pdf
 
The engineers for the Ariane 5 followed the principle of redundant .pdf
The engineers for the Ariane 5 followed the principle of redundant .pdfThe engineers for the Ariane 5 followed the principle of redundant .pdf
The engineers for the Ariane 5 followed the principle of redundant .pdf
 
The emergence of cryptocurrencies, stablecoins, and other decentrali.pdf
The emergence of cryptocurrencies, stablecoins, and other decentrali.pdfThe emergence of cryptocurrencies, stablecoins, and other decentrali.pdf
The emergence of cryptocurrencies, stablecoins, and other decentrali.pdf
 
The Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdf
The Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdfThe Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdf
The Daily Tribune es el �nico diario que sirve a una regi�n de seis .pdf
 
The District of Columbia has 345 ICU beds under normal conditions, a.pdf
The District of Columbia has 345 ICU beds under normal conditions, a.pdfThe District of Columbia has 345 ICU beds under normal conditions, a.pdf
The District of Columbia has 345 ICU beds under normal conditions, a.pdf
 

Dernier

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Dernier (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

The Fibonacci sequence begins with 0 and then 1 follows. All subsequ.pdf

  • 1. 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: the output is: Note: Use recursion and DO NOT use any loops. this is the code: 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; startNum = scnr.nextInt(); System.out.println("fibonacci(" + startNum + ") is " + fibonacci(startNum)); } }