3 回答
TA贡献1859条经验 获得超6个赞
只需做一个简单的更改并在计算后打印数字。
for (int i = 1; i <= maxNumber; ++i)
{
// System.out.print(previousNumber+" ");
int sum = previousNumber + nextNumber;
previousNumber = nextNumber;
nextNumber = sum;
System.out.print(previousNumber+" ");
}
TA贡献1799条经验 获得超6个赞
/*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] + " ");
}
}
}
添加回答
举报