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);
}
}
}
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);
}
}
}
相关文章推荐
- java程序标准增删改查示例
- 使用JAVA实现签名验证示例程序
- 提高java程序性能之垃圾收集
- 《重构》 — Java示例:影片出租店程序(5、单元测试)
- 《重构》 — Java示例:影片出租店程序(6、重构——引入状态模式)
- 一个用Dijkstra算法实现的路由算法的java程序——9 图信息文件示例
- 公钥加密,私钥解密示例程序(JAVA)
- JAVA GUI程序示例
- JAVA GUI程序示例
- eclipse远程调试java程序简单示例
- SHA-1和MD5示例程序 Java编写
- 使用.bat文件运行Java程序的一个示例
- 数字签名示例程序 Java编写
- 《重构》 — Java示例:影片出租店程序(1、重构前)
- java垃圾回收机制的程序理解
- Java的xpath示例程序
- LocalOS 0.1.1 版发布(内附本程序源码及Java版网游找CALL示例源码)
- Java:命令行运行Jar包程序的命令示例
- 《重构》 — Java示例:影片出租店程序(3、重构——分解并重组Statement)
- Java程序使用memcached配置与示例