Tuesday 5 February 2019

9.Program to print Fibonacci Series using for loop in java.


Description:
Write a sample code to print Fibonacci Series using for loop in java.


Code:
?
1
2
3
4
5
6
7
8

public class Fibonacci_Searies { public static void main(String args[]) { int febCount = 15; int[] feb = new int[febCount]; feb[0] = 0; feb[1] = 1; for (int i = 2; i < febCount; i++) { feb[i] = feb[i - 1] + feb[i - 2]; } for (int i = 0; i < febCount; i++) { System.out.println(feb[i] + ""); } } }


Output:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377

No comments:

Post a Comment