首页 > 其他 > 详细

36选7

时间:2015-12-08 10:05:19      阅读:192      评论:0      收藏:0      [点我收藏+]
import java.util.Random;

public class caiPiao {

    public static void main(String[] args) {

        int[] cai = new int[7];
        Random rand = new Random();

        // 生成

        for (int i = 0; i < 7; i++) // 循环7次,生成7个随机数
        {
            int temp = rand.nextInt(36);
            temp++; // 生成随机数

            // 解决重复问题
            int chf = 0;// 检索数组,记录重复次数

            for (int j = 0; j < 7; j++) {// 检查是否重复,有重复记录chf++

                if (temp == cai[j]) {
                    chf++;
                }

            }
            if (chf == 0) {
                cai[i] = temp;
            } else {
                i--;

            }

            //System.out.print(temp + "\t");

        }

        // 显示
        for (int i = 0; i < cai.length; i++) {
            System.out.print(cai[i] + "\t");
        }

        // TODO 自动生成的方法存根

    }

}

 

36选7

原文:http://www.cnblogs.com/youshashuosha/p/5028075.html

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