Java控制台实现斐波那契数列

import java.io.*;

public class Fibonacci

{


/**

* @param args

*/

public static void main(String[] args)

{



FBN fi = new FBN();

fi.f();

}


}

class FBN

{

public int i;

public int j;

public int b;

public FBN()

{

this.i = i;

this.j = j;

this.b = b;

try

{

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader br = new BufferedReader(isr);

System.out.println("需要数的个数");

b = Integer.parseInt(br.readLine());

System.out.println("请输入第一个数i");

i = Integer.parseInt(br.readLine());

System.out.println("请输入第二个数j");

j = Integer.parseInt(br.readLine());

}

catch (Exception e)

{

e.printStackTrace();

}


}

public void f()

{

int m;


System.out.println(i);

System.out.println(j);

for (int n = 0; n < b - 1; n++)

{

m = i + j;

i = j;

j = m;

System.out.println(m);

}

}

}


你可能感兴趣的:(Java控制台实现斐波那契数列)