首页 > 其他 > 详细

随机生成双色球号码

时间:2017-04-29 14:55:27      阅读:185      评论:0      收藏:0      [点我收藏+]

package com.lovo.homework;

public class NumberGenerator {

private int[] redBalls = new int[6];

private int blueBall;

public void run(){
for(int i = 0; i < 3; i++){
this.generateRedBall();
this.generateBlueBall();
this.showResult();
}
}

private void generateRedBall(){

for(int i = 0; i < this.redBalls.length; i++){
this.redBalls[i] = (int)(Math.random() * 33 + 1);
for(int j = 0; j < i; j++){
if(this.redBalls[i] == this.redBalls[j]){
i--;
break;
}
}
}
}

private void generateBlueBall(){
this.blueBall = (int)(Math.random() * 16 + 1);
}

private void showResult(){
String redBallMsg = "";
for(int i = 0; i < this.redBalls.length; i++){
redBallMsg += this.redBalls[i];
if(i != this.redBalls.length - 1){
redBallMsg += ",";
}
}

System.out.println("红球:" + redBallMsg);
System.out.println("篮球:" + this.blueBall);
}

}

随机生成双色球号码

原文:http://www.cnblogs.com/fengshaolingyun/p/6785136.html

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