import java.io.*;
public class u{
static int t;
public static int f(int n){
if(n<=1)  t=1;
     else {
f(n)=(f(n-1)+f(n-2));
t=f(n);
      } 
     return t; }public static void main(String args[] ){
int m,p;
u i=new u();
try{m=System.in.read();}catch(Exception e){System.out.println("Exception");}


p=u.f(m);System.out.println(p);

}}

解决方案 »

  1.   

    改成这样:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;/*
     * 创建日期 2006-9-25
     *
     * TODO 要更改此生成的文件的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */public class test {
    public int f(int n){
    if(n<=1)  
    return 1;
         else
         return (f(n-1)+f(n-2));
    } public static void main(String args[] ){
    try{
    int m = 0,p = 0;
    test i=new test();
    BufferedReader ib = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("please input:");
    String str = ib.readLine();
    m=Integer.parseInt(str);
    p=i.f(m);
    System.out.println("input:" + m + " result:" + p);
    }catch(Exception e){
    e.printStackTrace();
    System.out.println("Exception");
    }
    }
    }
      

  2.   

    死循环
    按楼上的来,递归一定要有返回,否则就是死循环
    通过键盘输入的数字是string型,要转为int型