Mavan pom文件引用依赖
-
<!-- hutool工具类-->
-
<dependency>
-
<groupId>cn.hutool
</groupId>
-
<artifactId>hutool-all
</artifactId>
-
<version>5.3.6
</version>
-
</dependency>
-
<!-- google java类库-->
-
<dependency>
-
<groupId>com.google.guava
</groupId>
-
<artifactId>guava
</artifactId>
-
<version>18.0
</version>
-
</dependency>
java 单类实现代码,在编辑器里,粘贴下面的代码。鼠标右键、run运行
-
-
import cn.hutool.core.util.RandomUtil;
-
import com.google.common.collect.Lists;
-
-
import java.util.
List;
-
-
/**
-
* @Author tarzan
-
* @Date 2021/4/1 14:43
-
* @Description 模拟双色球,随机生成若干住号码
-
*/
-
public
class DoubleColorBall {
-
-
-
/**
-
* 主方法
-
* */
-
public
static
void main(
String[] args) {
-
getDoubleColorBallNumber(
5);
-
}
-
-
/**
-
* 获取多注双色球号码
-
* */
-
public
static
void getDoubleColorBallNumber(
int num){
-
System.out.println(
"随机生成"+num+
"注双色球号码为:");
-
String resultNumber=
"";
-
for (
int i =
0; i < num; i++) {
-
System.out.println(
"【"+(i+
1)+
"】 "+resultNumber+getDoubleColorBallNumber());
-
}
-
-
}
-
-
/**
-
* 获取单注双色球号码
-
* */
-
public
static
String getDoubleColorBallNumber(){
-
String resultNumber=
"";
-
for (
int i =
0; i <
6; i++) {
-
String ballNumber= RandomUtil.randomEle(getRedBalls())+
"\t";
-
resultNumber=resultNumber+ballNumber;
-
}
-
return resultNumber+RandomUtil.randomEle(getBlueBalls());
-
}
-
-
/**
-
* 获取红球球号集合
-
* */
-
public
static
List<
String> getRedBalls(){
-
return getBalls(
33);
-
}
-
-
/**
-
* 获取蓝球球号集合
-
* */
-
public
static
List<
String> getBlueBalls(){
-
return getBalls(
16);
-
}
-
-
/**
-
* 获取球号集合
-
* */
-
public
static
List<
String> getBalls(
int num){
-
List<
String> redBalls= Lists.newArrayList();
-
for (
int i =
1; i <=num; i++) {
-
int length=
String.valueOf(num).length();
-
String str =
String.format(
"%0"+length+
"d",i);
-
redBalls.add(str);
-
}
-
return redBalls;
-
}
-
}
结果图
转载:https://blog.csdn.net/weixin_40986713/article/details/115367035
查看评论