编译没有问题,执行出现了问题(高手帮帮忙啊!)
E:\JAVA\Test01>javac BubbleSort.javaE:\JAVA\Test01>java BubbleSort
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at BubbleSort.bubbleSort(BubbleSort.java:17)
at BubbleSort.main(BubbleSort.java:6)
原程序在这:
程序代码:public class BubbleSort
{
public static void main(String[] args)
{
int x1[]={10,60,30,20};
bubbleSort(x1);//对x1数组进行冒泡排序
display(x1);//对x1数组进行输出显示
System.out.println();//换行
}
public static void bubbleSort(int x[])
{
int temp;
for(int i=1;i<x.length;i++)//比较的趟次
{
for(int j=0;j<x.length;j++)//在某趟中逐对比较
{
if(x[j]<x[j+1])//从大到小排序
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
}
public static void display(int y[])
{
for(int i=0;i<y.length;i++)
System.out.print(y[i]+" ");
}
}









