You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicintgetFibonaciNumber(intn) {
switch(n) {
case1: return1;
case2: return1;
case3: return2;
case4: return3;
case5: return5;
case6: return8;
case7: return13;
default:
// good enough for the demo, lolreturn -1;
}
}
Code written at a startup
// TODO: add Javadoc comments/** * getFibonacciNumber */// TODO: Should we move this to a different file?publicintgetFibonacciNumber(intn) {
// TODO: Stack may overflow with recursive implementation, switch over to// iteration approach at some point?if (n < 0) {
// TODO: This should probably throw an exception. Or maybe just print// a log message?return -1;
} elseif (n == 0) {
// TODO: Generalize the initial conditions?return0;
} elseif (n == 1) {
return1;
} else {
// TODO: Spend some time with my family and kids, I've been at work for// over 48 hours straight.returngetFibonacciNumber(n - 1) + getFibonacciNumber(n - 2);
}
}
Code written at a large company
/** * getFibonacciNumber is a method that, given some index n, returns the nth * Fibonacci number. * @param n The index of the Fibonacci number you wish to retrieve. * @return The nth Fibonacci number. */publicCustomInteger64getFibonacciNumber(CustomInteger64n) {
FibonacciDataViewBuilderbuilder =
FibonacciDataViewBuilderFactory.createFibonacciDataViewBuilder(
newFibonacciDataViewBuilderParams(n, null, null, 0, null));
if (builder == FibonacciDataViewBuilderConstants.ERROR_STATE) {
thrownewFibonacciDataViewBuilderFactoryException();
}
FibonacciDataViewdataView = builder.generateFibonacciDataView(this);
if (dataView == FibonacciDataViewConstants.ERROR_STATE) {
thrownewFibonacciDataViewGenerationException();
}
returndataView.accessNextFibonacciNumber(null, null, null);
}