斐波那契数列计算
public int getNth(int nth) {
long timeBegin = System.currentTimeMillis();
int result = -1;
if (nth <= 0) {
System.out.println("Illeagal nth!");
} else {
if ( nth <= 2) {
result = nth == 1 ? 0 : 1;
} else {
int n1 = 0, n2 = 1;
int currNth = 3;
while (currNth <= nth) {
result = n1 + n2;
n1 = n2;
n2 = result;
currNth ++;
}
}
}
System.out.println("fibonacci nth = " + result + ", cosume time : "
+ (System.currentTimeMillis() - timeBegin));
return result;
}