随机生成双色球号码

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

}

posted @ 2017-04-29 14:21  风少凌云  阅读(785)  评论(0编辑  收藏  举报