Friday, April 5

Fibonacci series for given number in Java

Hi All,

Java program to find Fibonacci series of a given number



import java.io.*;
import java.util.*;

public class fibonacci {
public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter value of n: ");
    String st = reader.readLine();
    int num = Integer.parseInt(st);
    int f1=0,f2=0,f3=1;
    for(int i=1;i<=num;i++){
        System.out.println(f3);
        f1=f2;
        f2=f3;
        f3=f1+f2;
    }
}
}


Output:

~~~~~~

Enter value of n: 5
1
1
2
3
5

 

 


No comments:

Post a Comment

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...