⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 用java程序现实的计算斐波那契数列的非递归程序
💻 JAVA
字号:
/*
 * Main.java
 *
 * Created on 2007年3月17日, 下午12:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package sore;

import java.io.*;

/**
 *
 * @author Administrator
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static int F(int n) {
        int sum;
        if(n>=2)
            sum=F(n-2)+F(n-1);
        else
            if(n==1)
               sum=1;
            else
               sum=0;
        return sum;
    }
    
    public static void main(String[] args) throws IOException{
        // TODO code application logic here
        BufferedReader keyin = new BufferedReader( new          //接收字符
                    InputStreamReader(System.in));
        int num;
        do{
            System.out.println("请输入整数N(N>=0):");        //建立键盘上的输入
            num = Integer.parseInt(keyin.readLine());
            if(num<0)
            {
                System.out.println("输入错误!");
            }
        }while(num<0);
        long sum=F(num);
        System.out.println("结果为:"+sum);
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -