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

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);
}
}
}
posted on 2016-10-15 23:24  _故乡的原风景  阅读(182)  评论(0编辑  收藏  举报