,当我试图运行此代码我得到这个error..I不知道我错在哪里..异常线程“main” java.lang.ArrayIndexOutOfBoundsException:0误差在Java中
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at numericalComputatio.fibo.main(fibo.java:30)
package numericalComputatio;
public class fibo {
static double c = -0.618;
// double c = [(1-sqrt(5))/2] = - 0.618
/**
* Computes the fibonacci series
* @param n
* @return
*/
private static double fibo(int n){
if (n == 0)
return 1;
else if (n == 1)
return c;
else
{
double result = fibo(n - 1) + fibo(n - 2);
return result;
}
}
public static void main(String[] args) {
int n = 0;
double result = 0.0;
double result1 = 1.000000000;
if (args[0] != null)
n = Integer.parseInt(args[0]);
for(int i = 0; i<=n; i++)
{
result = fibo(i);
System.out.println("fib(" + i + ") = " + result + "Formula value = " + result1);
result1 = result1*c;
}
}
}
它不会走到这一步,因为它会在测试'ARGS [0]!= null'死亡。 – 2011-04-11 16:25:09
由于格式化,我错过了异常堆栈跟踪。在看到有罪行之后更正为否。 30 – OscarRyz 2011-04-11 16:28:59
我没有去stacktrace,只知道它正在评估上一行的args [0] :) – 2011-04-11 16:31:17