帮助我有一个需要解决的难题!我做了一个斐波那契数列,但我忘了包括 0 谁能帮我解决这个谜语?如果输入序列中的五个输出应该是 0,1,1,2,3 我应该改变什么来清理代码并获得所需的结果而不完全从头开始?
//Class Assignment 9 little Fibonacci series based on what input
//the user provides
import java.util.Scanner;
public class LittleFibonacci {
int number;// This declares an int variable
public static void main(String[] args){
//itnu is the new object
LittleFibonacci itnu = new LittleFibonacci ();
itnu.GetNumberInput();
}
public void GetNumberInput()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a number and that number will be a" +
" \nrepresentitive of the length of a sequence in the Fibonocci series.");
number = input.nextInt();
int f1, f2=0, f3=1;
for(int i = 1 ; i <= number ; i++ )
{
System.out.print(" "+f3+" ");
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
input.close();
}
}