class maopao2
{
public static void maopao(int[] arr)
{
for(int x=0; x<arr.length-1; x++)
{
int y=0;
for(; y<arr.length-x-1; y++)
{
if(arr[y]>arr[y+1])
{
int temp = arr[y];
arr[y] = arr[y+1];
arr[y+1] = temp;
}
}
System.out.print(arr[y]);
}
}
public static void main(String[] args)
{
int[] arr = {1,9,3,5,6,4,8,7,2};
maopao(arr);
}
} |
|