Java实现双色球(选号+开奖)

这是一个Java程序,实现了彩票投注的选择(自选或机选)和生成随机中奖号码的功能。用户可以选择购买方式,系统会验证所选号码是否中奖,并计算收益。程序包括号码生成、数据转换、中奖验证等模块。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package test01;
 
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
 
public class fname {
 
    static String[] storage = new String[100];
    static int k = 0;
 
    public static int[] GenrateWinningNub() {
        int[] twn = new int[6];
        int[] wn = new int[7];
        Boolean[] bool = new Boolean[34];
        for (int j = 0; j < 34; j++) {
            bool[j] = false;
        }
        for (int i = 0; i < 6; i++) {
            int temp = new Random().nextInt(33) + 1;// 产生1-33
            if (bool[temp] == false) {// 没有产生过
                twn[i] = temp;
                bool[temp] = true;
            } else
                i--;
        }
        Arrays.sort(twn);
        System.arraycopy(twn, 0, wn, 0, twn.length);
        wn[6] = new Random().nextInt(16) + 1;
        return wn;
    }
 
    public static void Menu() {
        System.out.println("请选择购买方式:1.自选号码投注 2.机选号码投注 3.退出");
        @SuppressWarnings("resource")
        int input = new Scanner(System.in).nextInt();
        switch (input) {
        case 1:
            storage[k++] = SelfChoice();
            break;
        case 2:
            storage[k++] = ComputerChoice();
            break;
        case 3: {
            System.out.println("选购结束,您选购的号码如下,祝您中奖");
            for (String str : storage) {
                if (str == null)
                    break;
                System.out.println(str);
            }
            System.out.println();
            return;
        }
        }
        Menu();
    }
 
    public static String ComputerChoice() { // 电脑产生一组随机号码
        System.out.println("计算机已经为您选好一组号码:");
        int[] temp = GenrateWinningNub();
        String str = "";
        for (int i : temp) {
            str += String.valueOf(i) + " ";
        }
        System.out.println(str);
        System.out.println("请输入投注倍数:");
        @SuppressWarnings("resource")
        String df = new Scanner(System.in).nextLine();
        str += "倍数:" + df;
        System.out.println(str);
        return str;
    }
 
    @SuppressWarnings("resource")
    public static String SelfChoice() {
        System.out.println("请输入你要选择的号码 中间以一个空格为分割 最后加注数");
        String str = new Scanner(System.in).nextLine();
        System.out.println("请输入投注倍数:");
        str = str + " 倍数:" + new Scanner(System.in).nextLine();
        System.out.println(str);
        return str;
    }
 
    public static int[][] ChangeData() {// 将storage转化为int[][]二维数组
 
        int[][] choiced = new int[storage.length][8];
        for (int i = 0; i < choiced.length; i++) {
            if (storage[i] == null) {
                break;
            }
            String[] str = storage[i].split(" ");
            for (int j = 0; j < choiced[0].length; j++)// j<6
            {
                if (j < 7) {
                    choiced[i][j] = Integer.valueOf(str[j]);
                } else {
                    choiced[i][j] = Integer.parseInt(str[j].split(":")[1]);
                }
            }
        }
        return choiced;
    }
 
    public static void VerifyWinning(int[][] choicednub, int[] winnub) {// 验证是否中奖以及中奖金额
    
        
    
            int Samered = 0;
            int Sameblue = 0;
            int Getbonus = 0;// 奖金
            int cost = 0;
 
            
                    for (int i = 0; i < choicednub.length; i++) {
                    
 
                        if (choicednub[i][0] == 0) {
                            break;
                        }
 
                        for (int j = 0; j < choicednub[0].length - 2; j++) {
 
                            for (int m = 0; m < 5; m++) {
 
                                if (winnub[m] == choicednub[i][j]) {
                                    Samered++;
                                }
                            }
                        }
 
                        if (choicednub[i][6] == winnub[6]) {
                            Sameblue = 1;
                        }
 
                        if (Sameblue == 0 && Samered <= 3) {
                            System.out.println("第" + (i + 1) + "组号码未中奖");
                        }
 
                        if (Sameblue == 1 && Samered <= 2) {
                            Getbonus += 5 * choicednub[i][7];
                            System.out.println("第" + (i + 1) + "组号码已中六等奖,中奖金额为倍数 "+choicednub[i][7]+"*5=" + 5 * choicednub[i][7] + " 元");
                        }
 
                        if ((Sameblue == 0 && Samered == 4) || (Sameblue == 1 && Samered == 3)) {
                            Getbonus += 10 * choicednub[i][7];
                            System.out.println("第" + (i + 1) + "组号码已中五等奖,中奖金额为倍数*10=" + 10 * choicednub[i][7] + " 元");
                        }
 
                        if ((Sameblue == 0 && Samered == 5) || (Sameblue == 1 && Samered == 4)) {
                            Getbonus += 200 * choicednub[i][7];
                            System.out.println("第" + (i + 1) + "组号码已中%%%%%%%%%%%%%%%%四等奖,中奖金额为倍数*200="
                                    + 200 * choicednub[i][7] + " 元");
                        }
 
                        if (Sameblue == 1 && Samered == 5) {
                            Getbonus += 3000 * choicednub[i][7];
                            System.out.println("第" + (i + 1) + "组号码已中@@@@@@@@@@@@@@@@@三等奖,中奖金额为倍数*3000="
                                    + 3000 * choicednub[i][7] + " 元");
 
                            System.out.println(Arrays.toString(choicednub[i]));
                        }
 
                        if (Sameblue == 0 && Samered == 6) {
                            Getbonus += 2000000 * choicednub[i][7];
                            System.out.println("第" + (i + 1) + "组号码已中$$$$$$$$$$$$$$$$$二等奖,中奖金额为倍数*2000000="
                                    + 2000000 * choicednub[i][7] + " 元");
 
                            System.out.println(Arrays.toString(choicednub[i]));
                        }
 
                        if (Sameblue == 1 && Samered == 6) {
                            Getbonus += 5000000 * choicednub[i][7];
                            System.out.println("第" + (i + 1) + "组号码已中******************一等奖,中奖金额为倍数*5000000="
                                    + 5000000 * choicednub[i][7] + " 元");
 
                            System.out.println(Arrays.toString(choicednub[i]));
                        }
                        cost += choicednub[i][7];
 
                        Samered = 0;
                        Sameblue = 0;
                    }
                    System.out.println();
                    System.out.println("您本次消费: " + cost * 2 + " 元,中奖 " + Getbonus + " 元");
                    if (Getbonus > cost * 2) {
                        System.out.println("您最终淨赚: " + (Getbonus - cost * 2) + " 元,祝愿您下次中奖");
                    }
                    if (Getbonus < cost * 2) {
                        System.out.println("您最终亏损: " + (cost * 2 - Getbonus) + " 元,祝愿您下次中奖");
                    }
                    if (Getbonus == cost * 2) {
                        System.out.println("您最终不赚也不亏,祝愿您下次中奖");
                    }
                
    }
 
    public static int[][] findbest(int count) {
        int[][] a = new int[count][8];
        for (int i = 0; i < count; i++) {
            int[] wn = GenrateWinningNub();
            System.out.println("第 " + (i + 1) + " 组 :" + Arrays.toString(wn));
            for (int j = 0; j < 7; j++) {
                a[i][j] = wn[j];
            }
            a[i][7] = 1;
        }
        return a;
    }
 
    public static void showwinnub(int[] winnub) {
             System.out.println("本次开奖号码为:");
                    for (int a : winnub) {
                        System.out.print(a + " ");
                    }
                    System.out.println();                
    }
 
    public static void main(String[] args) {
        Menu();// 选择
        int[][] shownub = ChangeData();// 二维int[][]数组记录号码以及倍数
        int[] winnub = GenrateWinningNub();// 产生中奖号码
        showwinnub(winnub);
        VerifyWinning(shownub, winnub);
        //VerifyWinning(findbest(10), winnub);
 
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

丿疾风灬回旋

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

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

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

打赏作者

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

抵扣说明:

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

余额充值