How do I implement a fibonacci sequence in java using try/catch logic?
Posted
by Lars Flyger
on Stack Overflow
See other posts from Stack Overflow
or by Lars Flyger
Published on 2010-05-07T18:11:29Z
Indexed on
2010/05/07
18:18 UTC
Read the original article
Hit count: 301
I know how to do it using simple recursion, but in order to complete this particular assignment I need to be able to accumulate on the stack and throw an exception that holds the answer in it.
So far I have:
public static int fibo(int index) {
int sum = 0;
try {
fibo_aux(index, 1, 1);
}
catch (IntegerException me) {
sum = me.getIntValue();
}
return sum;
}
fibo_aux is supposed to throw an IntegerException (which holds the value of the answer that is retireved via getIntValue) and accumulates the answer on the stack, but so far I can't figure it out. Can anyone help?
© Stack Overflow or respective owner