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);
}
}
}
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);
}
}
}
邮箱:wangh_2@sina.com