冒泡程序编译成功运行不了
冒泡程序编译成功运行不了,大家帮忙,谢谢程序代码:
public class bubblesort { public static void main(String []args) { int a[] = {21, 9, 45, 17, 33, 72, 50, 12, 41, 39}; int i; int j; int temp; int k; for (i=a.length; --i>=0;) { for (j=0; j<i; j++) { if (a[j] > a[j+i]) { temp = a[j]; a[j] = a[j +1]; a[j +1] = temp; } } } for (k=0; k<a.length; k++) { System.out.println("a["+ k +"]: " + a[k]); } } }
运行时显示:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at bubblesort.main(bubblesort.java:15)
[ 本帖最后由 羲和 于 2011-11-12 19:37 编辑 ]