随机数组排序

时间:2013-02-21 02:06:13

标签: arrays sorting

是否可以对以下代码的随机生成的整数数组进行排序(升序)?如果,那怎么样?

import java.util.Random;

public class RandomArraySorter {

        public static void main(String args[]){
        Random random = new Random();

        int array[] = new int[10];

        //number of integer spaces within the array:
        for(int i = 0; i < 10; i++){

        //random numbers from 1 to 100:
        array[i] = random.nextInt(100) + 1;

           System.out.print(array[i] + " ");
        }
    } //end of main
} //end of class

1 个答案:

答案 0 :(得分:2)

您可以使用以下方式排序:

Arrays.sort(array);