继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

java课程练习

zylnbhaw
关注TA
已关注
手记 1
粉丝 1
获赞 2

package com.imooc.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class Testsort {

public int qiusuijishu(int length)
{
    Random random=new Random();
    int k=random.nextInt(length);
    return k;
}
public String shengchengsuijizifuchuan(int changdu)
{
    String choose="1234567890abcdefghijklmnopqrstABCDEFGHIGKLMNOPQRST";
    StringBuffer sBuffer=new StringBuffer();
    int length=choose.length();
    for(int i=0;i<changdu;i++)
    {
        sBuffer.append(choose.charAt(qiusuijishu(length-1)));
    }
    return sBuffer.toString();
}
public void sort3()
{
    Random two=new Random();
    List<String> newlist3=new ArrayList<String>();
    for(int i=0;i<10;i++)
    {
        int k=two.nextInt(62);
        newlist3.add(shengchengsuijizifuchuan(k));
    }
    System.out.println("排序前字符串为");
    shuchu(newlist3);
    Collections.sort(newlist3);
    System.out.println("排序后的字符串为");
    shuchu(newlist3);
}
public void shuchu(List newlist)
{
    for (Object url : newlist) {
        System.out.println(url);
    }
}
public static void main(String[] args)
{
    Testsort one=new Testsort();
            one.sort3();
}

}

打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP