//冒泡排序   不知道是什么原因.编译无错,解释有错!!
public class SortDemo
{
public static void main(String args[]) 
{
   int[] intArray={48,21,47,53,87,19,42,73,3,74,445,};
   for(int i=intArray.length+1;--i>0;)
   {
      for(int j=0;j<i;j++)
      {
       if(intArray[j]>intArray[j+1])//老是这句出错,不知错在那里?求大家帮忙
       {
       int temp;
       temp=intArray[j];
       intArray[j]=intArray[j+1];
       intArray[j+1]=temp;
       }
      }
   }
   for(int i=intArray.length+1;--i>0;)
   {
    System.out.print(" "+intArray[i]);
   }
}
}

解决方案 »

  1.   

    //冒泡排序 不知道是什么原因.编译无错,解释有错!!
    public class Bubble {
    public static void main(String args[]) {
    int[] intArray = { 48, 21, 47, 53, 87, 19, 42, 73, 3, 74, 445, };
    for (int i = intArray.length-1; i > 0;i--) {
    for (int j = i; j >0; j--) {
    if (intArray[j] < intArray[j - 1])//老是这句出错,不知错在那里?求大家帮忙
    {
    int temp = intArray[j];
    intArray[j] = intArray[j - 1];
    intArray[j - 1] = temp;
    }
    }
    }
    for (int i =0;i<intArray.length ;i++) {
    System.out.print(" " + intArray[i]);
    }
    }
    }
      

  2.   

    不好意思,我调成了wizardblue(不死鱼)的程序了
      

  3.   

    public class SortDemo
    {
    public static void main(String args[]) 
    {
       int[] intArray={48,21,47,53,87,19,42,73,3,74,445,};
       for(int i=intArray.length+1;--i>0;)//关键在这句,使i=12,数组下标越界
       {
          for(int j=0;j<i;j++)
          {
                       //这里j+1导致j会=12
           if(intArray[j]>intArray[j+1])//老是这句出错,不知错在那里?求大家帮忙
           {
           int temp;
           temp=intArray[j];
           intArray[j]=intArray[j+1];
           intArray[j+1]=temp;
           }
          }
       }
       for(int i=intArray.length+1;--i>0;)
       {
        System.out.print(" "+intArray[i]);//这里一开始i就越界了
       }
    }
    }
    帮你改了下public class Test1
    {
    public static void main(String args[]) 
    {
       int[] intArray={48,21,47,53,87,19,42,73,3,74,445,};
       for(int i=intArray.length+1;--i>0;)
       {
          for(int j=1;j<i-1;j++)
          {
           if(intArray[j-1]>intArray[j])//老是这句出错,不知错在那里?求大家帮忙
           {
           int temp;
           temp=intArray[j];
           intArray[j]=intArray[j-1];
           intArray[j-1]=temp;
           }
          }
       }
       for(int i=intArray.length;i-->0;)
       {
        System.out.print(" "+intArray[i]);
       }
    }
    }