public class ArrayDemo{
public static void main(String[] args) {
int data [] = new int [] {89,4,5,1,45,49,75,12,46,3,6,8,10};
sort(data);
printArray(data);
}
public static void sort(int arr[]){
for(int x = 0; x < arr.length-1;x++){
for(int y = 0; y <arr.length-1 ; y++){
if(arr[y]>arr[y+1]){
int temp = arr[y];
arr[y] = arr[y+1];
arr[y+1] = temp;
}
}
}
}
public static void printArray(int temp[]){
for(int x = 0; x < temp.length; x++){
System.out.print(temp[x]+"、");
}
System.out.println();
}
}
java实现数组的排序
最新推荐文章于 2024-07-22 08:37:45 发布