blob: 9891721408e7fdf73ff30626979f33e7e92e5d15 [file] [log] [blame]
public class Test {
public int fib(int n) {
switch (n) {
case 0:
return 0;
// you can comment out the next three lines -- same thing
case 1:
case 2:
return 1;
default:
int a;
int b = 1;
int c = 2;
n -= 3;
while (n-- > 0) {
a = b;
b = c;
c = a + b;
}
return c;
}
}
}