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

2023-05-06,,

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);

}

}

}

java小程序 示例 菲薄垃圾数列的相关教程结束。

《java小程序 示例 菲薄垃圾数列.doc》

下载本文的Word格式文档,以方便收藏与打印。