Java Program to Print FIBONACCI Series using FOR LOOP
In this tutorial we will write a Java program to java program to print fibonacci series using for loop. A fibonacci series is a number series where the next value in the series is the addtion of previous 2 numbers.
E.g – 0, 1, 1, 2, 3, 5, 8, 13, 21,……………………………..
We will be using For Loop to print the Fibonacci Series and we will print only n numbers (you can take this no from users) of the fibonacci series.
Java program to Print Fibonacci Series –
//Q1) print first 7 numbers of the fibonacci series // 0 + 1 + 1 + 2 + 3 + 5 + 8 + package javaapplication4; public class JavaApplication4 { public static void main(String[] args) { int a = 0; int b = 1; int c; for(int i = 0; i<5 ; i++) { System.out.print(a+" "); c = a+b; a=b; b=c; } } }
Output
0 1 1 2 3