博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
随机生成双色球号码
阅读量:4554 次
发布时间:2019-06-08

本文共 870 字,大约阅读时间需要 2 分钟。

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

转载于:https://www.cnblogs.com/fengshaolingyun/p/6785136.html

你可能感兴趣的文章
一点小问题
查看>>
pytest 10 skip跳过测试用例
查看>>
MVC身份验证及权限管理
查看>>
It was not possible to find any compatible framework version
查看>>
gulp与webpack的区别
查看>>
offset--BUG
查看>>
CSS选择器
查看>>
POJ_3667 线段树+lazy (线段树经典题)
查看>>
Android获取图片资源的4种方式
查看>>
找工作---操作系统常考知识点总结【PB】
查看>>
解决ionic <ion-nav> rootParams获取不到参数
查看>>
Python学习02 列表 List
查看>>
[DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用
查看>>
python爬虫-淘宝商品密码(图文教程附源码)
查看>>
centos6.3下如何搭建LAMP环境
查看>>
C#的一些基础内容
查看>>
nodejs概述
查看>>
H3C PAP验证配置示例
查看>>
oracle-Dbca数据库模板
查看>>
ionic 轮播
查看>>