-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathprogram.java.txt
More file actions
29 lines (29 loc) · 1014 Bytes
/
program.java.txt
File metadata and controls
29 lines (29 loc) · 1014 Bytes
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
//Author @ArjunBhandari.666
//github.com/ArjunBhandari-666
//alternative solution to problem 4 irrespective of case input
import java.io.*;
import java.util.Scanner;
class fibonacci
{
public static void main()
{
Scanner scan=new Scanner(System.in);
System.out.println("\fEnter a number to check");
int x=scan.nextInt(),a=1,n; //using 3 variables, namely 'i','a',and 'n' to exchange term values
for(int i=2;i<99999;i=n)
{
n=i+a; // next term
if(x==a)
{
System.out.println("Fibbonaci continuation is \n"+a+"\t"+i+"\t"+(a+i)+"\t"+((a+i)+i)+"\t"+(((a+i)+i)+(a+i))+"\t"+((((a+i)+i)+(a+i))+((a+i)+i)));
n=99999;
}
if(i>x && x!=a)
{
System.out.println("NOT A FIBONACCI TERM");
n=99999;
}
a=i; //updating previous term
}
}
}