In this program ,you will learn how to print Fibonacci series in java language. The Fibonacci series is a series where next digit is sum of previous digits.
Go the java links: https://www.pyapiras.in/2020/06/fibonacci-series-in-java.html
Source Code:
- public class FibonocciNumber {
- public static void main(String[] args) {
- try (Scanner input = new Scanner (System.in)) {
- int n,i,first = 0,second = 1,fibo;
- System.out.println("How many number: ");
- n = input.nextInt();
- System.out.println(first+"\n"+second);
- for(i=3;i<=n;i++) {
- fibo = first + second;
- first = second;
- second = fibo;
- System.out.println(fibo);
- }
- }
- }
- }
output:
How many number: 3011How many number: 1201123581321345589
0 comments:
Post a Comment