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

来源:互联网 发布:摄像头app软件下载 编辑:程序博客网 时间:2024/05/20 06:23
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);
}
}
}
0 0
原创粉丝点击