数组的冒泡排序
import java.util.Arrays;
public class ArraysTest {
public static void main(String[] args) {
int[] arr = {12, 32, 4, 43, 65, 24, 23};
System.out.println(Arrays.toString(arr));
for (int x = 0; x < arr.length - 1; x++) {
for (int i = 0; i < arr.length - 1 - x; i++) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
二、还可以直接调用Arrays中的方法sort完成字符串的排序
import java.util.Arrays;
public class ArraysTest {
public static void main(String[] args) {
int[] arr = {12, 32, 4, 43, 65, 24, 23};
System.out.println(Arrays.toString(arr));
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));