Monday, 28 September 2015

Febonic Series Program in Java

/**
 *
 */
import java.io.*;
//import java.util.*;
/**
 *
 *
 */
public class Fibonacci  {

/**
* @param args
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int f1=0,f2=1,f=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the febonic series...till the numbers you are looking at .... !");
int i = Integer.parseInt(br.readLine());
System.out.println("The value of the i is " +i);
while(f<i){
f=f1+f2;
f2=f1;
f1=f;
System.out.println("The value of f is " +f);
//++i;
}
}

}

Out put:-

Enter the febonic series...till the numbers you are looking at .... !
10
The value of the i is 10
The value of f is 1
The value of f is 1
The value of f is 2
The value of f is 3
The value of f is 5
The value of f is 8
The value of f is 13

No comments:

Post a Comment