//Mason Marnell - Fibo
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import static java.lang.System.in;
import java.util.Scanner;
class Fibanaci {
public static long finoGreedy(long data)
{
int n1 = 1;
int n2 = 2;
int nextnum = n1 + n2;
for (int i = 3; i < data; i++) {
nextnum = n1 + n2;
n1 = n2;
n2 = nextnum;
}
return nextnum;
}
public static long fiboRecursion(long data)
{
if(data == 1) return 1;
if(data == 2) return 1;
return fiboRecursion(data-1) + fiboRecursion(data-2);
}
public static void main(String[] args) {
Scanner keyb = new Scanner(in);
System.out.println("Enter which fibonaci number you want");
int num = keyb.nextInt();
System.out.println(finoGreedy(num));
System.out.println(fiboRecursion(num));
}
}
Comments