Java选择排序
package com.ycy1;
public class Test02 {
public static void main(String[] args) {
int[] array = {8,6,7,3,9,1};
Test02.selectSort(array);
}
public static void selectSort(int[] array) {
System.out.println("排序前的数组:");
for(int i : array) {
System.out.print(i + " ");
}
for(int i = 0; i < array.length - 1;i ++) {
for(int j = i + 1; j < array.length;j ++) {
if(array[j] < array[i]) {
int temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}
System.out.println();
System.out.println("排序后的数组:");
for(int i : array) {
System.out.print(i + " ");
}
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210125141105603.png)