当前位置 博文首页 > HI,我是小瑞!:JAVA 生成随机数数组,并排序输出

    HI,我是小瑞!:JAVA 生成随机数数组,并排序输出

    作者:[db:作者] 时间:2021-08-09 10:00

    package com.koal.test;??
    ?
    import java.util.Arrays;??
    ?
    /**?
    ?*??
    ?* @author hp?
    ?* 排序?
    ?*/?
    ?
    public class Sort {??
    ??????
    ??? //要生成多少个随机数??
    ??? int num = 10;??
    ??? int[] suiji = new int[num];??
    ??????
    ??? //产生随机数组??
    ??? public void ProduceNum(){??
    ??????? for(int i=0;i<num;i++){??
    ??????????? int j = (int)(Math.random()*100);??
    ??????????? suiji[i] = j;??
    ??????? }??
    ??? }??
    ?
    ??? /**?
    ???? * @param args?
    ???? */?
    ??? public static void main(String[] args) {??
    ??????? Sort sort = new Sort();???
    ??????? sort.ProduceNum();??
    ??????? Arrays.sort(sort.suiji);??
    ??????????
    ??????? for(int i=0;i<sort.num;i++){??
    ??????????? System.out.println(sort.suiji[i]);??
    ??????? }??
    ??? }??
    ?
    }?


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xiaxiaorui2003/archive/2009/09/12/4547124.aspx

    cs