随机生成双色球彩票红,蓝数字

来源:互联网 发布:如何在做域名劫持 编辑:程序博客网 时间:2024/04/30 12:33
public class DoubleBallDemo2 {public static void main(String[] args) {String [] redPool = new String[33]; //红球池String [] bluePool = new String[16];//蓝球池redPool =getFullString(redPool);bluePool =getFullString(bluePool);System.out.println(Arrays.toString(doubleBall(redPool,bluePool)));//System.out.println(Arrays.toString(bluePool));}public static String[] getFullString( String [] ary){for ( int i = 0; i < ary.length; i++ ){char [] ch = {'0','0'};String s = Integer.toString(i+1); //字符串转字符char [] num =s.toCharArray(); //字符串转成数组 "1" -> {'1'}System.arraycopy(num, 0, ch, ch.length-num.length, num.length);String ball = new String(ch);ary[i] =ball;}return ary;}public static String [] doubleBall( String [] redPool, String [] bluePool ){boolean [] used = new boolean[redPool.length]; //使用的球存放在这里,标记TRUE,默认FALSEString [] all  = new String[7]; //存放红,蓝球Random r = new Random();for ( int i = 0; i < 6; i++ ){int  rdnum;do{rdnum  = r.nextInt(redPool.length);}while ( used[rdnum] );all[i]  = redPool[rdnum];used[rdnum] = true;}all[all.length-1]  = "99";Arrays.sort(all);all[all.length-1] = bluePool[r.nextInt(bluePool.length)];return all;}}