java随机字符补充版

原文:java随机字符补充版

源代码下载地址:http://www.zuidaima.com/share/1575831367224320.htm

今天在zuidaima看到一个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随机字符补充版


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值