用java的if、else实现3D福利彩票中奖游戏

1、程序规则要求

1、1中奖规则

3D中奖可分为三种情况:单选、组选3和组选6。
"单选"奖:投注号码与当期公布的中奖号码的3位数按位数全部相同;
即中得直选奖。如开奖号是123,中出123
"组选3"奖:当期摇出的中奖号码3位数中有任意两位数字相同的;
且投注号码与中奖号码的数字相同,顺序不限,即中得"组选3"奖。
如开奖号是122,中出212、221、122。
"组选6"奖:当期摇出的中奖号码中3位数各不相同;
且投注号码的三个数字与当期中奖号码相同,顺序不限,
即中得"组选6"奖。如开奖号为123,中出321、132、213、231、312、123。

1、2奖金分配

"单选"投注:中奖金额除北京每注980元,其他省市每注1000元;
"组选3"投注:中奖金额为每注320元(上海每注333元);
"组选6"投注:中奖金额为每注160元(上海每注166元)。

2、过程分析

1、3D的中奖号码使用Math.random()生成随机数实现,该方法使用本意是随机生成一个
【0,1)的小数,用其乘以10再强转为int类型,即可得到【0,10)之间的整数;
随机三次模拟得到系统生成的三位中奖号码;
2、当用户输入其选择的号码时,只有一种三个一致的豹子可以直接确定用户购买的为直选;
中奖号码唯一,无需询问用户直选或组选;
3、当用户输入非豹子号码,引入变量存储用户选择直选或组选,直选则需号码依次相等;
4、当用户确定为组选时,优先以组6的规则判断该号码是否中奖(组6范围大于组3,组6中奖,组3一定中奖);
组6中奖有6种情况可以中奖;
例如:中奖号假设123   则有123 132 213 312  231 321 此包含了组3组6。
5、若中奖后再判断中的金额为组3还是组6;

3、程序代码实现


import java.util.Scanner;
public class TestTicket{
   
	public static void main(String[] args){
   
		int a1 = (int)(Math.random()*10);
		int a2 = (int)(Math.random()*<
以下是福利彩票双色球Java实现: ```java import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class DoubleColorBall { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入您要购买的彩票注数:"); int n = input.nextInt(); int[][] tickets = new int[n][7]; for (int i = 0; i < n; i++) { System.out.println("请输入第" + (i + 1) + "注彩票的号码:"); for (int j = 0; j < 6; j++) { System.out.print("请输入第" + (j + 1) + "个红球号码(1-33):"); int redBall = input.nextInt(); while (redBall < 1 || redBall > 33) { System.out.print("输入有误,请重新输入第" + (j + 1) + "个红球号码(1-33):"); redBall = input.nextInt(); } tickets[i][j] = redBall; } System.out.print("请输入蓝球号码(1-16):"); int blueBall = input.nextInt(); while (blueBall < 1 || blueBall > 16) { System.out.print("输入有误,请重新输入蓝球号码(1-16):"); blueBall = input.nextInt(); } tickets[i][6] = blueBall; } System.out.println("您购买的彩票号码为:"); for (int i = 0; i < n; i++) { System.out.print("第" + (i + 1) + "注:"); for (int j = 0; j < 6; j++) { System.out.print(tickets[i][j] + " "); } System.out.println("蓝球:" + tickets[i][6]); } int[] result = getResult(); System.out.println("本期开奖号码为:" + Arrays.toString(Arrays.copyOf(result, 6)) + " 蓝球:" + result[6]); int totalMoney = n * 2; int totalPrize = 0; for (int i = 0; i < n; i++) { int prize = getPrize(tickets[i], result); totalPrize += prize; if (prize > 0) { System.out.println("第" + (i + 1) + "注彩票中奖了,中奖金额为:" + prize + "元"); } } System.out.println("您一共下注" + totalMoney + "元,累计中奖" + totalPrize + "元"); } public static int[] getResult() { int[] result = new int[7]; Random random = new Random(); for (int i = 0; i < 6; i++) { int redBall = random.nextInt(33) + 1; while (contains(result, redBall, i)) { redBall = random.nextInt(33) + 1; } result[i] = redBall; } Arrays.sort(result, 0, 6); int blueBall = random.nextInt(16) + 1; result[6] = blueBall; return result; } public static boolean contains(int[] array, int value, int length) { for (int i = 0; i < length; i++) { if (array[i] == value) { return true; } } return false; } public static int getPrize(int[] ticket, int[] result) { int redCount = 0; int blueCount = 0; for (int i = 0; i < 6; i++) { if (contains(result, ticket[i], 6)) { redCount++; } } if (ticket[6] == result[6]) { blueCount = 1; } if (redCount == 6 && blueCount == 1) { return 10000000; } else if (redCount == 6) { return 500000; } else if (redCount == 5 && blueCount == 1) { return 3000; } else if (redCount == 5 || (redCount == 4 && blueCount == 1)) { return 200; } else if (redCount == 4 || (redCount == 3 && blueCount == 1)) { return 10; } else if (blueCount == 1) { return 5; } else { return 0; } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落日晓余晖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值