java实现双色 * 票游戏
作者:大精灵丶帕克 发布时间:2022-06-29 12:39:45
标签:java,双色球,彩票
综合案例开发:模拟双色 * 票游戏,供大家参考,具体内容如下
玩法说明:
双色球投注区分为红球号码区和蓝球号码区,红球号码范围为01~33,蓝球号码范围为01~16。双色球每期从33 个红球中开出6个号码(不能重复),从16个蓝球中开出1个号码作为中奖号码,双色球玩法即是竞猜开奖号码的6 个红球号码和1个蓝球号码,顺序不限。 用户输入红球和蓝球号码,程序输出该用户中几等奖。
代码实现:
import java.util.Random;
import java.util.Scanner;
public class SimulatedLottery {
public static void main(String[] args) {
//单注最高奖金
int maxMoney = 500;
//输入蓝球的号码
System.out.print("请输入你购买的蓝球号码:");
Scanner input = new Scanner(System.in);
int blueBall = input.nextInt();
//输入红球的数组
int[] redBall = new int[6];
System.out.print("请输入你购买的红球号码(不重复):");
for (int i = 0; i < redBall.length; i++) {
redBall[i] = input.nextInt();
}
//输出输入值
System.out.println("----------------");
System.out.print("你购买的红球号码是:");
for (int i = 0; i < redBall.length; i++) {
System.out.print(redBall[i]+",");
}
System.out.println();
System.out.println("你购买的蓝球号码是:"+blueBall);
System.out.println("---正在产生中奖号码---");
//生成的蓝球号码
Random numsRandom = new Random();
int blueBallRandom = numsRandom.nextInt(16)+1;
//生成红球的号码
int[] redBallRandom = new int[6];
int index = redBallRandom.length;
int inputRandom = 0;
int k = 0;
while (index>0) {
if (exist(redBallRandom, inputRandom)) {
//在数组中存在,更换一个随机数
inputRandom = numsRandom.nextInt(33)+1;
}else {
//在数组中不存在
redBallRandom[k] = inputRandom;
k++;
index--;
}
}
//输出中奖号码
System.out.println("蓝球的中奖号码是:"+blueBallRandom);
System.out.print("红球的中奖号码是:");
for (int i = 0; i < redBallRandom.length; i++) {
System.out.print(redBallRandom[i]+",");
}
System.out.println();
//统计和蓝球相等的个数
int blueCount = 0;
if (blueBall == blueBallRandom) {
blueCount = 1;
}
//统计和红球相等的个数
int redCount = 0;
for (int i = 0; i < redBallRandom.length; i++) {
if (redBall[i] == redBallRandom[i]) {
redCount++;
}
}
//判断是否中奖
if (blueCount == 0 && redCount <= 3) {
//未中奖
System.out.println("很遗憾,您未中奖, * 害人,请勿上头!");
//中奖
}else if(blueCount == 1 && redCount < 3) {
System.out.println("恭喜你,中了六等奖,您的奖金为5元");
}else if((blueCount == 1 && redCount == 3) || (blueCount == 0 && redCount == 4)) {
System.out.println("恭喜你,中了五等奖,您的奖金为10元");
}else if((blueCount == 1 && redCount == 4) && (blueCount == 0 && redCount == 5)) {
System.out.println("恭喜你,中了四等奖,您的奖金为200元");
}else if(blueCount == 1 && redCount == 5) {
System.out.println("恭喜你,中了三等奖,您的奖金为3000元");
}else if(blueCount == 0 && redCount == 6) {
System.out.println("恭喜你,中了二等奖,您的奖金为"+(int)(maxMoney*0.3)+"万");
}else if(blueCount == 1 && redCount == 6 ) {
System.out.println("恭喜你,中了一等奖,您的奖金为"+maxMoney+"万");
}
}
//判断数组中是否存在某数的方法,存在返回true
public static boolean exist(int[] redBallRandom, int inputRandom) {
for (int i = 0; i < redBallRandom.length; i++) {
if(redBallRandom[i] == inputRandom) {
return true;
}
}
return false;
}
}
来源:https://blog.csdn.net/dajinglingpake/article/details/106972018


猜你喜欢
- 一、HttpBasic模式的应用场景HttpBasic登录验证模式是Spring Security实现登录验证最简单的一种方式,也可以说是最
- 前言通常在DAL层我们都需要把DataTable转换为List<T>让调用者尽可能的好用,尽量的不用关心数据库的字段等,所以我们
- import java.io.FileNotFoundException;import java.io.FileOutputStream;i
- C#WinForm程序设计之图片浏览器,这次我们一起做一个图片查看器,这个图片查看器的原始图如下:我们首先来介绍一下这个原始图的构成:左边上
- 环境搭建创建Maven项目。pom.xml文件中引入RocketMQ依赖。<dependencies>  
- WPF中有一个DrawingContext类,该类提供了很多画法方法,例如DrawLine,DrawText,DrawRectangle等。
- springboot 配置多个jndi数据源1.在application.properties中,添加jndi配置如下图2.新建dataSo
- 在一些耗时的操作过程中,在长时间运行时可能会导致用户界面 (UI) 处于停止响应状态,用户在这操作期间无法进行其他的操作,为了不使UI层处于
- 本文所述为一个C#使用iCSharpcode压缩的使用类,经测试效果不错。分享给大家供大家参考之用。具体方法如下:1.参数类using Sy
- 相关函数:longjmp, siglongjmp, setjmp表头文件:#include <setjmp.h>函数定义:int
- 问题现象今天使用mybatis遇到个很奇怪的问题,我使用一个参数@param("threshold"),类型是java的
- 沉浸式状态栏的来源就是很多手机用的是实体按键,没有虚拟键,于是开了沉浸模式就只有状态栏消失了。于是沉浸模式成了沉浸式状态栏。我们先来看下具体
- Android 11文件管理权限申请Android 11文件管理权限申请,为什么需要这个权限,因为在Android 11后,无法直接在SDc
- 杨辉三角的规律:1.每行的数据个数和在第几行一样。2.每行第一个数和最后一个数都是1.3.每行除了第一个数据和最后一个数据 其他数据的值等于
- 本文实例讲述了C#中datagridview使用tooltip控件显示单元格内容的方法。分享给大家供大家参考,具体如下:代码如下:using
- 下截JNative组件jnative.sourceforge.net/ 到这里下载JNative开源项目,我下载的是1.3.2解压JNati
- 项目要求基于Broadcast,BroadcastReceiver等与广播相关的知识实现简单的音乐播放功能,包括音乐的播放、暂停、切换、进度
- 场景:同一个用户在2秒内对同一URL的提交视为重复提交。思考逻辑:1.从数据库方面考虑,数据设计的时候,某些数据有没有唯一性,如果有唯一性,
- 阅读收获理解SpringBoot自动配置原理一、SpringBoot是什么SpringBoot 的诞生就是为了简化 Spring 中繁琐的
- IDEA时跳转到.class的解决项目背景:jdk1.8软件环境:IDEA问题:两个不同的项目,在A项目中写了一个实体类。B项目中引用。我想