class ArryDemo12
{
public static void main(String[] args)
{
int [] arr={34,19,11,109,1,56};
paiXu(arr);
for (int x=0; x<=arr.length-1 ; x++)
{
System.out.println(arr[x]);
}
}
public static void paiXu(int [] arr)
{
for (int x=0; x<arr.length-1 ; x++)
{
int num=arr[x];
int index=x;
for (int y=x+1; y<arr.length; y++)
{
if (num>arr[y])
{
num=arr[y];
index=y;
}
}
int temp = num;
num = arr[x];
arr[x] = temp;
}
}
}
为什么结果是
1
1
1
1
1
56
{
public static void main(String[] args)
{
int [] arr={34,19,11,109,1,56};
paiXu(arr);
for (int x=0; x<=arr.length-1 ; x++)
{
System.out.println(arr[x]);
}
}
public static void paiXu(int [] arr)
{
for (int x=0; x<arr.length-1 ; x++)
{
int num=arr[x];
int index=x;
for (int y=x+1; y<arr.length; y++)
{
if (num>arr[y])
{
num=arr[y];
index=y;
}
}
int temp = num;
num = arr[x];
arr[x] = temp;
}
}
}
为什么结果是
1
1
1
1
1
56