首页 > 编程语言 > 详细

java14:玩彩票

时间:2015-10-02 11:23:57      阅读:234      评论:0      收藏:0      [点我收藏+]
package day14;

import java.util.Arrays;
import java.util.Random;

public class Demo01 {

	public static void main(String[] args) {
		int[] balls = gen();
		System.out.println(Arrays.toString(balls));
	}

	public static int[] gen() {
		int[] pool = new int[34];
		for (int i = 1; i < pool.length; i++) {
			pool[i - 1] = i;
		}
		boolean[] used = new boolean[pool.length];
		int[] balls = new int[6];
		int index = 0;
		Random random = new Random();
		int i;
		do {
			i = random.nextInt(pool.length);
			if (used[i])
				continue;
			balls[index++] = pool[i];
			used[i] = true;
		} while (index != balls.length);
		Arrays.sort(balls);
		balls = Arrays.copyOf(balls, balls.length + 1);
		balls[balls.length - 1] = pool[random.nextInt(16)];
		return balls;
	}
}


本文出自 “浪漫的偷笑” 博客,请务必保留此出处http://lmdtx.blog.51cto.com/6942028/1699872

java14:玩彩票

原文:http://lmdtx.blog.51cto.com/6942028/1699872

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!