您的位置:首页 > 其它

利用堆栈输出递归序列的若干项:Fibonacci序列

2009-11-21 16:54 351 查看
package com.fuxi.test.collection;
/**
* 利用堆栈输出递归序列的若干项:Fibonacci序列
* 堆栈是一种“先进后出”的特殊序列
*/
import java.util.Stack;

public class StackTest {

public static void main(String[] args) {
Stack<Integer> stack = new Stack<Integer>();
stack.push(new Integer(1));
stack.push(new Integer(1));
int k =1;
while(k<10){
Integer F1 = stack.pop();
int f1 = F1.intValue();
Integer F2 = stack.pop();
int f2 = F2.intValue();
Integer temp = new Integer(f2+f1);
System.out.println(temp.toString());
stack.push(temp);
stack.push(F2);
k++;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: