用 java 编写求Fibonacci数列前N个数

还有一个是Readadatesuppliedasmonth,day,andyear,e.g.7/29/53.Convertittotheform:29thJuly1953... 还有一个是
Read a date supplied as month, day, and year, e.g. 7/29/53.
Convert it to the form : 29th July 1953. Don’t check the validity of date.
( Write three methods
String Print_day ( int day)
String Print_month( int month)
String Print_year( int year) )
救命啊~~
展开
 我来答
柔润且坦荡的闺秀0p
推荐于2016-01-10
知道答主
回答量:5
采纳率:0%
帮助的人:0
展开全部
public class Fibonacci{
public static void main(String[] args){
int num = Integer.parseInt(args[0]);
for(int i=1; i<=num; i++)
System.out.print(getFib(i)+" ");
System.out.println();
}
//后面的数等于前面二个数的和

public static int getFibRec(int n){
if(n < 0)return 0;
if(n <=2)
return 1;
else
return getFibRec(n-2) + getFibRec(n-1);
}
public static int getFib(int n){
if(n < 0)return 0;
if(n <=2)return 1;
int f = 1;
int f1 = 1;
int f2 = 1;
for(int i=3; i<=n; i++){
f = f1 + f2;
f1 = f2;
f2 = f;
}
return f;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式