您的位置:首页 > 编程语言 > Java开发

简单的斐波那契数列

2017-08-23 15:42 351 查看
package com.sq.test;

import java.util.Scanner;

public class Test2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count = input.nextInt();
int a = 0;
int b = 1;
boolean is = true;
if(count==0){
System.out.println(0);
}else if(count==1){
System.out.println(1);
}else{
for(int i = 2;i<=count;i++){
if(i%2==0){
a=a+b;
is = false;
}else{
b=a+b;
is = true;
}
}
if(is){
System.out.println(b);
}else{
System.out.println(a);
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java 算法 斐波那契