Any idea why my code is giving out the wrong answer after the first few?
My university professor provided us with this to go by and I feel I followed it?
If for example I was to use:
System.out.println(fibr(8));
System.out.println(fibr(9));
System.out.println(fibr(10));
The console prints out: 11 34 20
Which of course is not the fibonacci numbers in those places
public static int fibr(int n) {
if(n<0) return 0;
if(n==0) return 0;
if(n==1) return 1;
if(n==2) return 1;
//is odd
// n is = or > 3 and NOT (n divided by 2 with remainder of 0 (making it even))
if(n >= 3 && !(n % 2 == 0)) {
int a;
a = fibr((n+1)/2) * fibr((n+1)/2);
a = a + (fibr((n-1)/2) * fibr((n-1)/2));
return a;
}
//is even
if(n >= 3 && (n % 2 == 0)) {
int a;
a = fibr((n/2)+1) + fibr((n/2)-1) * fibr(n/2);
return a;
}
return 0;
}
Help what's wrong cri
