-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFibonacci_Portal.java
50 lines (47 loc) · 1007 Bytes
/
Fibonacci_Portal.java
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
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
class Fib
{
int num;
Fib(int n)
{
this.num = n;
for(int i=2;i<=n;i++)
{
Fibonacci(i);
}
}
void Fibonacci(int n)
{
int j =0,k=1;
while(j <= n)
{
int temp = j;
j = k; k = k+temp;
if(j==n){
System.out.println( (int)Math.floor(j) + " is a fibonacci number ");
powerOfTwo(n);
}
}
}
void powerOfTwo(int n){
for(int i=1;i<=n;i++)
{
if(n == power(i))
{
System.out.println((int)Math.ceil(n) + " is a power of two");
}
}
}
int power(int i)
{
if(i==0)return 1;
return 2 * power(i-1);
}
}
public class Fibonacci_Portal {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
Fib fib = new Fib(n);
}
}