Code Written By A CS101 Student
计算机专业新生
public int fibonacci(int x) {
if(x=1) {
return 1:
} else if (x=2) {
return 1;
} else{
return fibonacci(x-1)+fibonacci(x-2);
}
}
Code Written At AHackathon 哈哈
public int getfibonacciNumber(int n){
switch(n){
case 1: return 1;
case 2:return 1;
case 3: return 2;
case 4:return 3;
case 5: return 5;
case 6:return 8;
case 7: return 13;
default:
// good enough for the demo, 1ol
return -1;
}
}
Code Written At A Startup 新手起步的写法
// TODO add Javadoc comments/**
*getFibonacciNumber*/
// ToDo Should we move this to a different file?
public int getFibonacciNumber(intn){
// ToDo Stack may overflow with recursive implementation, switch over to// iteration approach at some point?
if(n < o) {
// TODO This should probably throw an exception. Or maybe just print// a log message? return -1;
} else if(n== 0) {
// TODO Generalize the initial conditions? return o;
} else if (n=1) {
return 1:} else {
// ToDo Spend some time with my family and kids,I've been at work for// over 48 hours straight.
return getFibonacciNumber(n-1)+getFibonnaciNumber(n-2);
}
}
Code Written At A Large Company 大公司的写法
/**
*getfibonacciNumber is a method that, given some index n, returns the nth
* Fibonacci number.
* eparamn The index of the Fibonacci number you wish to retrieve.
* @return The nth Fibonacci number.
*/
public CustomInteger64 getFibonacciNumber(CustomInteger64n){
FibonacciDataViewBuilder builder=
FibonacciDataViewBuilderFactorycreateFibonacciDataViewBuilder{
new FibonacciDataViewBuilderParams(n,null,null,0,null));
if (builder==FibonacciDataViewBuilderConstantsERROR STATE
throw new FibonacciDataViewBuilderFactoryException();
}
FibonacciDataView dataView=builderGenerateFibonacciDataView(this);
if (dataView==FibonacciDataViewConstantsERROR STATE){
throw new FibonacciDataViewGenerationException();
}
return dataView.accessNextFibonacciNumber(nullnull,null);
}
Code Written By A Math PhD.
public int getFibonacciNumber(int n) {
return (int)divide(subtract(exponentiate(phi(),n),exponentiate(psi(),n))
subtract(phi(),psi()));
}
public double exponentiate(double a,double b) {
if(equal(b,zero())) {
return one();
} else{
return multiply(a,exponentiate(a,subtract(b,one()))):
}
}
public double phi() {
return divide(add(one(),sqrt(add(one(),one(),one(),one(),one()))),
add(one(),one()));
public double psi() {
return subtract(one(),phi());
}
Code Written By Your Cat
public static final int UNITE=1: public static final int UNITED=2
// meowwwww meow
public int meow(int KITTENS OF THE WORLD){
// MEOW
if (KITTENS OF THE WORLD<UNITED){
return KITTENS OF THE WORLD;
} else {
// meeoowwwwwwwww
// meoooowwwwwwwwwwwwwwwwwwwwww
return meow(KITTENS OF THE WORLD-UNITE)
+meow(KITTENS OF THE WORLD-UNITED);
}
}
haha
本文由 mdnice 多平台发布