您的位置:首页 > 移动开发 > 微信开发

java小程序 示例 菲薄垃圾数列

2016-10-15 23:24 429 查看
package com.test;

import java.util.Scanner;

import org.junit.Test;

import com.sun.xml.internal.ws.api.pipe.NextAction;

public class TestSwitch {

@Test
public void test() {
Scanner sc = new Scanner(System.in);
try {
while (true) {
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
System.out.print(testFibo(i) + " ");
}
System.out.println("");
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("输入不合法");
}
}

private long testFibo(long n) {
if (n < 3) {
return 1;
} else {
return testFibo(n - 1) + testFibo(n - 2);
}
}

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