Java选择排序

时间久了,就不记得了。闲来无事,抄记于此。

代码如下:

 1 class test {
 2     static void sort(int[] nums){
 3         for(int i = 0; i < nums.length; i++){
 4             for(int j = i+1; j < nums.length; j++){
 5                 if(nums[i] < nums[j]){
 6                     int temp = nums [i];
 7                     nums[i] = nums[j];
 8                     nums[j] = temp;
 9                 }
10             }
11         }
12     }
13 }

调用方法代码如下:

1 public class nums {
2     public static void main(String[] args){
3         int []nums = {1,2,9,14,0,9};
4         test.sort(nums);
5         for(int x = 0;x<nums.length;x++){
6             System.out.print(nums[x]+",");
7         }
8     }
9 }

 

posted @ 2013-05-14 16:27  Dimdusk  阅读(428)  评论(2编辑  收藏  举报