AXIN的gravatar头像
AXIN 2013-11-21 14:41:28

java随机字符补充版

   今天在zuidaimai看到一个java随机字符生成demo,正好要用,但发现不完整,重新整理一下,分享给有需要的朋友

public static void main(String[] args) {    
        //String s = RandomNum.getRandomNumStr(5);
        //System.out.println(s);
        System.out.println("生成5个含有5个字符的字符串:");
        RandomNum.SuiJiZiFuChuan(5,5);
        System.out.println("生成3个含有6个字符的字符串:");
        RandomNum.SuiJiZiFuChuan(6,3);
        System.out.println("生成任意1到20个含有任意1到10个字符的字符串:");
        RandomNum.SuiJiZiFuChuan((int)(20*Math.random()),(int)(10*Math.random()));
        System.out.println("随机性生成字符:");
        int i=0;
        while(i<(int)(10*Math.random())){
            RandomNum.SuiJiZiFuChuan((int)(20*Math.random()),1);
            i++;
        }
    }    

    public static void SuiJiZiFuChuan(int x,int y){
        for(int j=0;j<y;j++){
            for(int i=0;i<x;i++){
                int a=(int)(100*Math.random()+100*Math.random());
                while(true){
                    if(a>96&a<123)
                        break;
                    else
                        a=(int)(100*Math.random()+100*Math.random());
                }
                System.out.print((char)a);
            }
            System.out.println();
        }
    }

 

执行结果:

 

java随机字符补充版


打赏

最代码最近下载分享源代码列表最近下载
最代码最近浏览分享源代码列表最近浏览
JiaoTianLe  LV1 2021年11月23日
tmdgdx  LV9 2021年9月26日
2196316269  LV10 2021年2月24日
luohaipeng  LV23 2019年11月19日
likaizzk 2019年9月18日
暂无贡献等级
gwl  LV8 2019年5月16日
LikL9420  LV12 2019年1月25日
爱情的本质  LV15 2019年1月22日
秋得嘛得  LV5 2018年12月11日
xiahaoyu  LV8 2018年11月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友