- import java.util.Stack;
- public class Demo {
- public static void main(String[] args) {
- Stack st = new Stack();
- int count = Integer.valueOf(args[0]).intValue();
- int temp;
- Integer first = new Integer(3);
- Integer second = new Integer(8);
- st.add(first);
- st.add(second);
- for (int i = 0; i < count - 2; i++) {
- temp = first.intValue() + second.intValue();
- st.add(new Integer(temp));
- first = second;
- second = new Integer(temp);
- }
- System.out.println("输出这个系列的前" + count + "个数:");
- Object result[] = st.toArray();
- int wanghang = 0;
- for (int i = result.length - 1; i >= 0; i--) {
- System.out.print(st.pop() + " ");
- wanghang++;
- if (wanghang % 5 == 0) {
- System.out.println("\n");
- }
- }
- }
- }
复制代码 |