package com.hui_mao;
import java.util.Arrays;
public class Demo2 {
public static void main(String[] args) {
int[] arr = {45,59,25,78,36,15,78,59,45,9,3,99,23,4};
String old_arr = Arrays.toString(arr);
System.out.println(old_arr);
//正序排列
for (int i = 1; i < arr.length; i++) {
for (int j = arr.length-i; j >=0; j--) {
if (arr[j]<arr[j-1]) {
int temp;
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
}
}
}
String new_arr = Arrays.toString(arr);
System.out.println(new_arr);
//倒序排列
for (int i = 1; i < arr.length; i++) {
for (int j = arr.length-i; j >=0; j--) {
if (arr[j]>arr[j-1]) {
int temp;
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
}
}
}
String arr_old = Arrays.toString(arr);
System.out.println(arr_old);
}
}
|
|