Fibonacci series, named after Italian mathematician named Leonardo Pisano Bogollo, later known as Fibonacci, is a series (sum) formed by Fibonacci numbers denoted as Fn.
The numbers in Fibonacci sequence are given as: 0, 1, 1, 2, 3, 5, 8, 13, 21, 38, . . . In a Fibonacci series, every term is the sum of the preceding two terms, starting from 0 and 1 as first and second terms. In some old references, the term '0' might be omitted.
We find applications of the Fibonacci series around us in our day-to-day lives. It is also found in biological settings, like in the branching of trees, patterns of petals in flowers, etc.
We are going to generate fibonacci series upto a given number using Java.
import java.util.Scanner;
public class Fibonacci {
public static void main(String args[]){
int a=0,b=1,c=0,input;
Scanner sc = new Scanner(System.in);
System.out.println("Fibonacci series needs to be genrated upto ? : ");
input = sc.nextInt();
System.out.println(a);
System.out.println(b);
for(int i=0;i<=input-3;i++){
c=a+b;
System.out.println(c);
a=b;
b=c;
}
}
}
Comments
Post a Comment