Just provide the coding where it says: // PLEASE START YOUR METHOD HERE // *****
ID: 3898268 • Letter: J
Question
Just provide the coding where it says:
// PLEASE START YOUR METHOD HERE
// *********************************************************
// *********************************************************
//PLEASE END YOUR METHOD HERE
// PLEASE START YOUR OUTPUT HERE
// *********************************************************
// *********************************************************
//PLEASE END YOUR OUTPUT HERE
All sub-parts need to be answered. All the codes are provided. Must be in Java.
Check this link for the question: https://imgur.com/a/DG4JunX
Check this link for the code provided already: https://imgur.com/a/yByMALJ
Explanation / Answer
Given below is the code for the question. Please note that in the provided sample input/output, there is a mistake. For input 2, the output should be 1 and not 2.
From that line onwards till n = 10, the numbers have skipped one position. Let me know if you are confused.
The program does not prompt anything ... ... After you run the program, simply type any number from 0 to 10 and see what the output is ...
It should match corresponding to 0, 1, 1, 2, 3, 5 , 8, 13, 21, 34, 55
Request you to always provide copyable code i.e. text format rather than image to avoid retyping and loosing existing comments.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
import java.util.Scanner;
public class PoD {
public static int findFibonacci(int n)
{
int f0, f1, f2 = 0;
if(n == 0 )
return 0;
else if(n == 1)
return 1;
else
{
f0 = 0;
f1 = 1;
for(int i = 2; i <= n; i++)
{
f2 = f0 + f1;
f0 = f1;
f1 = f2;
}
return f2;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
System.out.println(findFibonacci(n));
in.close();
System.out.println("END OF OUTPUT");
}
}
output
====
9
34
END OF OUTPUT
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.