java双色球

红球 33 个球 (01~33) 取 六 蓝球 16 个球 (01~16) 取 一 Random r = new Random(); String[] balls ={"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33"}; boolean[] used = new boolean[balls.length]; String[] ball = new String[6]; int num = 1; for(int i=0;i<ball.length;i++){ int index = r.nextInt(balls.length);//0~32 while(used[index]){ index = r.nextInt(balls.length); } used[index]=true; ball[i]=balls[index]; } Arrays.sort(ball); ball = Arrays.copyOf(ball,ball.length+1); int index = r.nextInt(16); ball[ball.length-1]=balls[index]; System.out.println(Arrays.toString(ball));

你可能感兴趣的:(java)