java数组怎么倒循环_java – 用于数组倒计时的反向循环
我收到錯(cuò)誤..
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at Reverse.main(Reverse.java:20).
語法沒有錯(cuò),所以我不確定為什么編譯時(shí)會出錯(cuò)?
public class Reverse {
public static void main(String [] args){
int i, j;
System.out.print("Countdown\n");
int[] numIndex = new int[10]; // array with 10 elements.
for (i = 0; i<11 ; i++) {
numIndex[i] = i;// element i = number of iterations (index 0=0, 1=1, ect.)
}
for (j=10; j>=0; j--){ // could have used i, doesn't matter.
System.out.println(numIndex[j]);//indexes should print in reverse order from here but it throws an exception?
}
}
}
總結(jié)
以上是生活随笔為你收集整理的java数组怎么倒循环_java – 用于数组倒计时的反向循环的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql galera status_
- 下一篇: sql server 按照日期自动生成单