//Write Java Program to Print Fibonacci Series upto N Number
//programming789.blogspot.com/
import java.util.Scanner;
public class Fibonacci
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter 'N' value :");
int n = Integer.parseInt(scan.nextLine());
int a = -1;
int b = 1;
int c = 0;
int temp
System.out.println("The Fibonacci Series are :");
for(int i=1; i<=n; i++)
{
c = a + b;
temp = a;
a = b;
b = c;
System.out.println(c);
}
}
}
● Save the file as Fibonacci.java.
Output:
Enter 'N' value :
12
The Fibonacci Series are :
0
1
1
2
3
5
8
13
21
34
55
89
//programming789.blogspot.com/
import java.util.Scanner;
public class Fibonacci
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter 'N' value :");
int n = Integer.parseInt(scan.nextLine());
int a = -1;
int b = 1;
int c = 0;
int temp
System.out.println("The Fibonacci Series are :");
for(int i=1; i<=n; i++)
{
c = a + b;
temp = a;
a = b;
b = c;
System.out.println(c);
}
}
}
● Save the file as Fibonacci.java.
Output:
Enter 'N' value :
12
The Fibonacci Series are :
0
1
1
2
3
5
8
13
21
34
55
89