- class Select_Sort {
- public static void main(String[] args) {
- int[] arr = {1,3,43,5,4,8,23,12,14,33,28,89};
- for (int i = 0;i<arr.length ;i++ ) {
- for (int j = 1+i;j<arr.length ;j++ ) { //将数组元素从小到大排序
- if (arr[j]<arr[i]) {
- int temp = arr[j];
- arr[j] = arr[i];
- arr[i] =temp;
- }
- }
- }
- print(arr);
- }
- //数组遍历
- public static void print(int[] arr){
- System.out.print("[");
- for (int i = 0;i<arr.length ;i++ ) {
- if (i==arr.length-1) {
- System.out.print(arr[i]+"]");
- break;
- }
- System.out.print(arr[i]+",");
- }
- }
- }
复制代码
用到了 for 循环 数组的遍历及打印 俩变量值得的交换 基础知识而已 大神略过 |
|