import java.math.*;
public class selectarithmetic 
{
public static void main(String args[]) //throws Exception(e)
{
int i,temp,j;
int array[] = {4,2,45,64,22,64,8,64,15};
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)

if(array[j]>array[j+1])
{
temp = array[j];
    array[j] = array[j+1];
    array[j+1] = temp;
}
}
System.out.println("排序后的数为:");
    for(j=0;j<9;j++)
   {
    System.out.println("ee"+array[j]);
   }

}}

解决方案 »

  1.   

    int i,temp,j; 
    int array[] = {4,2,45,64,22,64,8,64,15}; 
    for(i=0;i <9;i++) 

    for(j=0;j <9-i;j++) if(array[j]>array[j+1]) // 这里是两个j?  

    temp = array[j]; 
        array[j] = array[j+1]; 
        array[j+1] = temp; 

      

  2.   


    public static void main(String args[]) // throws Exception(e)
    {
    int i, temp, j;
    int array[] = { 4, 2, 45, 64, 22, 64, 8, 64, 15 };
    for (i = 0; i < 9; i++) {
    for (j = 0; j < 8 - i; j++) //9-i时,数组发生越界了啊,我这里改成了8-i,能实现你要的效果
    if (array[j] > array[j + 1]) {
    temp = array[j];
    array[j] = array[j + 1];
    array[j + 1] = temp;
    }
    }
    System.out.println("排序后的数为:");
    for (j = 0; j < 9; j++) {
    System.out.println("ee" + array[j]);
    } }
      

  3.   

    for(i=0;i <array.length;i++) 

    for(j=0;j <array.length-i;j++) 建议楼主这么写