/*
需求: int[ ] arr = {37,92,54,18,76};
要求把数字按照从小到大排序后成为int[ ] arr2= {18,37,54,76,92};
*/
public class ArraysDemo {
public static void main(String[] args) {
int[ ] arr = {37,92,54,18,76};
//对数组排序
for (int x = 0; x < arr.length-1; x++) {
for (int y = 0; y < arr.length-1-x; y++) {
if(arr[y]>arr[y+1]){
arr[y] = arr[y]^arr[y+1];
arr[y+1] = arr[y]^arr[y+1];
arr[y] = arr[y]^arr[y+1];
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
|
|