码迷,mamicode.com
首页 > 其他好文 > 详细

随机生成双色球号码

时间:2017-04-29 15:11:58      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:his   号码   and   result   str   lov   sys   rand   void   

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);
}

}

随机生成双色球号码

标签:his   号码   and   result   str   lov   sys   rand   void   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!