어떤 이유로이 오류가 발생합니다.배열 인덱스가 경계를 벗어남 오류
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at Assignment25.main(Assignment25.java:80)
public static void main (String[] args){
long[] array = new long[7];
for (int i = 0; i < 6; i++){
int thefib = 39;
array[i] = fib(thefib);
thefib++;
}
int counter = 0;
int counter1 = 1;
for(int i = 0; i < 6; i++){
long start = System.currentTimeMillis();
gcd(array[counter], array[counter1]);
long end = System.currentTimeMillis();
long time = end - start;
System.out.println("GCD time for " + (counter + 39) + " and " + (counter1 +
39) + " is " + time);
counter++;
counter1++;
}
counter = 0;
counter = 1;
for(int i = 0; i < 6; i++){
long start1 = System.currentTimeMillis();
gcd2(array[counter], array[counter1]);
long end1 = System.currentTimeMillis();
long time1 = end1 - start1;
System.out.println("GCD2 time for " + (counter + 39) + " and " + (counter1 +
39) + " is " + time1);
counter++;
counter1++;
}
}
}
이유는 당신이 배열 외부의 인덱스를 사용하는 것입니다. – m0skit0