Sponsor

banner image

recent posts

Write a Java Program for Fibonacci series.

Answer: Fibonacci series is a series of numbers where after the initial two numbers, every occurring number is the sum of two preceding numbers.
For Example 0,1,1,2,3,5,8,13,21………
1import java.util.Scanner;
2 
3public class Fibonacci {
4    public static void main(String[] args) {
5        int num, a = 0,b=0, c =1;
6        Scanner in = new Scanner(System.in);
7        System.out.println("Enter the number of times");
8        num = in.nextInt();
9        System.out.println("Fibonacci Series of the number is:");
10        for (int i=0; i<=num; i++) {
11            a = b;
12            b = c;
13            c = a+b;
14            System.out.println(a + "");    //if you want to print on the same line, use print()
15        }      
16    }
17}
Output:
Enter the number of times
9
Fibonacci Series of the number is:
0
1
1
2
3
5
8
13
21
34
Write a Java Program for Fibonacci series.  Write a Java Program for Fibonacci series. Reviewed by D kumar on September 19, 2019 Rating: 5

Search

My Blog List

My Blog List

Hey guy's follow us on blog & social media( fb, insta,twitter, linkedin...) to get notifications about latest updates.

Followers

Powered by Blogger.