class Test5
{
public static void main(String[] args)
{
int [] arr={3,5,8,2,15,12,45};
getPaiLie(arr);
getPaiXu(arr);
getPaiLie(arr);
}
public static void getPaiXu(int[]a){
for(int x= 0;x<a.length-1;x++){ //a.length-1 少循环最后一次
for(int y=x+1;y<a.length;y++){//x+1 跟邻居比+1;
if (a[x]>a[y])
{
int t=a[x];
a[x]=a[y];
a[y]=t;
}
}
}
}
public static void getPaiLie(int []b){
System.out.print("[");
for (int x=0;x<b.length;x++ )
{
if(x!=b.length-1)
System.out.print(b[x]+",");
else System.out.println(b[x]+"]");
}
}
}
{
public static void main(String[] args)
{
int [] arr={3,5,8,2,15,12,45};
getPaiLie(arr);
getPaiXu(arr);
getPaiLie(arr);
}
public static void getPaiXu(int[]a){
for(int x= 0;x<a.length-1;x++){ //a.length-1 少循环最后一次
for(int y=x+1;y<a.length;y++){//x+1 跟邻居比+1;
if (a[x]>a[y])
{
int t=a[x];
a[x]=a[y];
a[y]=t;
}
}
}
}
public static void getPaiLie(int []b){
System.out.print("[");
for (int x=0;x<b.length;x++ )
{
if(x!=b.length-1)
System.out.print(b[x]+",");
else System.out.println(b[x]+"]");
}
}
}