How to create Fibonacci Sequence in Java
- by rfkrocktk
I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
The problem is that I can't really make this work in any other language. I'd like to make it work in Java, since I can pretty much translate it into the other languages I use from there. This is the general thought:
public class FibonacciAlgorithm {
private Integer a = 0;
private Integer b = 1;
public FibonacciAlgorithm() {
}
public Integer increment() {
a = b;
b = a + b;
return value;
}
public Integer getValue() {
return b;
}
}
All that I end up with is doubling, which I could do with multiplication :(
Can anyone help me out? Math pwns me.