forked from deepanshdubey/JavaAssignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.java
More file actions
40 lines (36 loc) · 1.02 KB
/
Fibonacci.java
File metadata and controls
40 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Author : Deepansh Dubey.
//Date : 2/09/2021.
//Purpose : To print fibbonacci series upto a given number.
import java.io.*;
class Fibonacci
{
void series(int x)
{
int i=x-2, a=0, b=1, c;
if (x<3)
{
System.out.println("Hahaha! Played Smart....\nEnter atleast 3 terms to get the series.");
}
else
{
System.out.print("The fibonacci series upto "+ x + " terms is:-\n\t" + a + "\t" + b);
while(i!=0)
{
c=a+b;
a=b;
b=c;
i--;
System.out.print("\t"+c);
}
}
}
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;
System.out.println("Please enter the number of terms of the series");
n=Integer.parseInt(br.readLine());
Fibonacci ob=new Fibonacci();
ob.series(n);
}
}