0114练习 彩票、验证码、双色球的随机数 输出
生活随笔
收集整理的這篇文章主要介紹了
0114练习 彩票、验证码、双色球的随机数 输出
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//生成彩票數(shù)
System.out.println("生成的彩票數(shù):");Random cp = new Random();for(int n=0;n<7;n++){System.out.print(" " + cp.nextInt(33));}System.out.println();
?
//生成驗(yàn)證碼String m = new String ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");//創(chuàng)建并初始化字符串Random yzm = new Random();//創(chuàng)建隨機(jī)數(shù)//第一種 int a=yzm.nextInt(61);//取一個(gè)隨機(jī)數(shù)int b=yzm.nextInt(61);int c=yzm.nextInt(61);int d1=yzm.nextInt(61);String s1=m.substring(a, a+1);//聲明字符串,截取隨機(jī)數(shù)與下一個(gè)數(shù)String s2=m.substring(b, b+1);String s3=m.substring(c, c+1);String s4=m.substring(d1, d1+1);String ss=s1+s2+s3+s4;//將隨機(jī)輸出的四個(gè)數(shù)連起來(lái) System.out.println(ss); //輸出//第二種:for循環(huán)方法System.out.println("驗(yàn)證碼:"); for(int n =0;n<4;n++){ int i = yzm.nextInt(m.length()); //定義變量i=一個(gè)隨機(jī)數(shù),隨機(jī)數(shù)的最大值是字符串m的長(zhǎng)度System.out.print(m.substring(i,i+1));//在字符串m截取i,i+1中的數(shù)//通過(guò)for循環(huán)4次輸出四位驗(yàn)證碼}?
轉(zhuǎn)載于:https://www.cnblogs.com/sjxx/p/5130823.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的0114练习 彩票、验证码、双色球的随机数 输出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 正则匹配 【】用法
- 下一篇: 【转】hadoop深入研究:(十一)——