我已经生成了一个程序,该程序可以用用户通过键盘给定的限制来计算斐波那契数列,但是我遇到了一个问题,因为我已经要求该数列从1开始,而不是从0开始。我怎样才能做到这一点?我的斐波那契数列显示的是1,而不是0?
X = X.values.reshape(-1, 1)
y = y.values.reshape(-1, 1)
clf.fit(X,y)
答案 0 :(得分:0)
使用int previousNumber = 1;
,它将从1开始。
答案 1 :(得分:0)
只需进行简单的更改并在计算后打印数字即可。
for (int i = 1; i <= maxNumber; ++i)
{
// System.out.print(previousNumber+" ");
int sum = previousNumber + nextNumber;
previousNumber = nextNumber;
nextNumber = sum;
System.out.print(previousNumber+" ");
}
答案 2 :(得分:0)
/*Java Program to find the FibonacciSeries */
public class FibonacciSeries {
public static void main(String a[]){
int limit = 15; /* give limit here */
int[] feb = new int[limit];
feb[0] = 0;
feb[1] = 1;
/* store all elements in array feb[] */
for(int i=2; i < limit; i++){
feb[i] = feb[i-1] + feb[i-2];
}
/* print all array elements */
for(int i=0; i< limit; i++){
System.out.print(feb[i] + " ");
}
}
}
答案 3 :(得分:0)
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.print("Enter the number of terms: ");
int count=scanner.nextInt();
scanner.close();
int firstTerm=1;
int secondTerm=2;
int nextTerm;
System.out.println("-----------------------");
System.out.print("Fibonacci Series: ");
System.out.print(firstTerm+","+secondTerm);
for(int i=3; i<=count; i++) {
nextTerm=firstTerm+secondTerm;
System.out.print(","+nextTerm);
firstTerm=secondTerm;
secondTerm=nextTerm;
}
}