java——双色球控制台版

双色球控制台版

技术需要

  • 双重数组
  • for、while循环
  • if switch 分支判断
  • break continue 循环控制

时间不够再打一边电子档,

如果大家有问题可以私聊或者留言问我,

电子版有点乱,(。・_・。)ノI’m sorry~

整体代码在最后,

好记性不如烂笔头,

希望大家还是自己整理一遍思路后再敲一遍

不要懒欧(*^▽^*)

1957f5acbc92675146cfeb88991bb8f

9110419b5d18dc3b8f09e424333a068

image-20220731162850773

de98f32c7f410e329e8b81a7d0cd6c53dfd603f3f50840733f41fb10cd3a85

de98f32c7f410e329e8b81a7d0cd6c5

eb6edf6bac4dcd4bde0ae0efd5bd574

be5edd7b6b95a1f7e7d070dfae4b309

5ada3ca82a00b8e71c6cd43ddfce6e3

6c67c815002f4941d07c2a422f88c67

b7d332dba5634564ce9ab961ed5bd49

变量创建

Scanner sc = new Scanner(System.in);
        int menu = 0;

        int[][] buy = new int[200][8];
        int buy_RedCount = 0;
        int buy_RedTemp = 0;
        int buy_BlueTemp = 0;
        int buy_MultipleTemp = 0;
        int buy_Count = 0;
        char buy_Continue = 'n';
        boolean redSort_Flag = false;

        boolean open_Flag = false;
        Random open_Random = new Random();
        int[] open = new int[7];
        int open_RedTemp = 0;
        int open_RedCount = 0;

        int view_RedCount = 0;
        int view_BlueCount = 0;
        int[] view = {0, 0, 0, 0};
        int view_Multiple = 0;
        int view_Sum = 0;

欢迎界面

 //Welcome
        System.out.println("\n****** ******* ******* ******* ******* ******* *******");
        System.out.println("Welcome to Two-Color ball!欢迎━(*`∀´*)ノ亻!");
        System.out.println("****** ******* ******* ******* ******* ******* *******");

菜单及do-while

o1:
        do {
            System.out.println("Please select the function by numbers(*^▽^*)");
            System.out.println("1. Buy lottery;");
            System.out.println("2. View purchased numbers;");
            System.out.println("3. Open the price;;");
            System.out.println("4. View the Winners;");
            System.out.println("5. Exit;");
            menu = sc.nextInt();
            switch (menu) {
                    
            }

 			} while (true);

case1

case 1:
                    if (open_Flag){
                        System.out.println("\nJust able to buy lotteries before open price!!!\n");
                        break ;
                    }
                    System.out.println("\nBuy lottery:");
                    while (true) {
                        buy_RedCount = 0;
                        //red-ball
                        o2:
                        while (true) {
                            //input red-balls
                            System.out.println("Please input No." + (buy_Count + 1) + " lottery's red-ball's No." + (buy_RedCount + 1) + " number");
                            buy_RedTemp = sc.nextInt();
                            if (buy_RedTemp < 1 || buy_RedTemp > 31) {
                                System.out.println("\nPlease input the number between 1 and 31 again!!!\n");
                                continue;
                            } else {
                                for (int i = 0; i < buy_RedCount; i++) {
                                    if (buy_RedTemp == buy[buy_Count][i]) {
                                        System.out.println("\nCan't select the same ball!!!");
                                        System.out.println("Please input the number again!!!\n");
                                        continue o2;
                                    }
                                }
                                buy[buy_Count][buy_RedCount] = buy_RedTemp;
                                buy_RedCount++;
                                if (buy_RedCount == 6) {
                                    for (int i = 0; i < buy_RedCount - 1; i++) {
                                        for (int i1 = 0; i1 < buy_RedCount - 1 - i; i1++) {
                                            if (buy[buy_Count][i1] > buy[buy_Count][i1 + 1]) {
                                                buy_RedTemp = buy[buy_Count][i1];
                                                buy[buy_Count][i1] = buy[buy_Count][i1 + 1];
                                                buy[buy_Count][i1 + 1] = buy_RedTemp;
                                                redSort_Flag = true;
                                            }
                                        }
                                        if (!redSort_Flag) {
                                            break;
                                        }
                                    }
                                    break o2;
                                }
                            }

                        }

                        //blue-ball
                        while (true) {
                            System.out.println("Please input the blue-ball number:");
                            buy_BlueTemp = sc.nextInt();
                            if (buy_BlueTemp < 1 || buy_BlueTemp > 16) {
                                System.out.println("\nPlease input the number again!!!\n");
                                continue;
                            } else {
                                buy[buy_Count][buy_RedCount] = buy_BlueTemp;
                                break;
                            }
                        }

                        //multiple
                        while (true) {
                            System.out.println("Please input the multiple:");
                            buy_MultipleTemp = sc.nextInt();
                            if (buy_MultipleTemp < 2) {
                                System.out.println("\nPlease input the number more than 1!!!\n");
                                continue;
                            } else {
                                buy[buy_Count][buy_RedCount + 1] = buy_MultipleTemp;
                                break;
                            }
                        }

                        buy_Count++;
                        //continue
                        System.out.println("\nWhether what to buy a lottery again?(y/n)");
                        buy_Continue = sc.next().charAt(0);
                        if (buy_Continue == 'y' || buy_Continue == 'Y') {
                            System.out.println();
                            continue;
                        } else {
                            System.out.println("\nAbout exit purchase system...");
                            System.out.println("Good luck!\n");
                            break;
                        }


                    }
                    break;

case2

case 2:
                    System.out.println("\nView purchased numbers:");
                    for (int i = 0; i < buy_Count; i++) {
                        System.out.println("--------------------Lottery_" + (i + 1) + "------------------");
                        System.out.print("Red-Ball Numbers : ");
                        for (int j = 0; j < buy_RedCount; j++) {
                            System.out.print(buy[i][j] + "\t");
                        }
                        System.out.println();
                        System.out.print("Blue-Ball Numbers : ");
                        System.out.println(buy[i][buy_RedCount]);
                        System.out.print("Multiple Numbers : ");
                        System.out.println(buy[i][buy_RedCount + 1]);
                    }
                    System.out.println();
                    break;

case3

case 3:
                    //just able to open once
                    if(open_Flag){
                        System.out.println("\nJust able to open the price once!!!\n");
                        break ;
                    }
                    System.out.println("\nOpen the price:");
                    //set flag
                    open_Flag = true;
                    //generalize the red-ball
                    o3:
                    while(true) {
                        //use open_RedTemp rather than directly use array
                        open_RedTemp = open_Random.nextInt(31) + 1;
                        //remove the same random
                        for (int i = 0; i < open_RedCount; i++) {
                            if (open_RedTemp == open[i]) {
                                continue o3;
                            }
                        }
                        open[open_RedCount] = open_RedTemp;
                        open_RedCount++;
                        //exit red-ball generalize
                        if(open_RedCount==6){
                            break ;
                        }
                    }
                    //sort red-ball
                    for (int i = 0; i < 6 - 1; i++) {
                        for (int i1 = 0; i1 < 6 - 1 - i; i1++) {
                            if (open[i1]>open[i1+1]){
                                open_RedTemp = open[i1];
                                open[i1] = open[i1 + 1];
                                open[i1 + 1] = open_RedTemp;
                            }
                        }
                    }
                    //generalize blue-ball
                    open[6] = open_Random.nextInt(16) + 1;
                    System.out.println("The winning red-ball numbers:");
                    for (int i = 0; i < 6; i++) {
                        System.out.print(open[i]+"\t");
                    }
                    System.out.println();
                    System.out.println("The winning blue-ball numbers:");
                    System.out.print(open[6]);
                    System.out.println("\n");
                    break;

case4

case 4:
                    if (buy_Count==0){
                        System.out.println("\nPlease buy lotteries firstly!!!\n");
                        break ;
                    }
                    if (!open_Flag){
                        System.out.println("\nPlease open price firstly!!!\n");
                        break ;
                    }
                    System.out.println("\nView the Winners:");
                    for (int i = 0; i < buy_Count; i++) {
                        view_RedCount = 0;
                        view_BlueCount = 0;
                        //output the buy lotteries
                        System.out.println("--------------The No."+(i+1)+" lottery---------------");
                        System.out.print("The red-ball numbers:");
                        for (int i1 = 0; i1 < 6; i1++) {
                            System.out.print(buy[i][i1]+"\t");
                        }
                        System.out.println();
                        System.out.print("The blue-ball numbers:" + buy[i][6]);
                        System.out.println();
                        //judge the red-ball number and sum
                        System.out.print("The red-ball winning numbers:");
                        for (int i1 = 0; i1 < open.length-1; i1++) {
                            for (int i2 = 0; i2 < 6; i2++) {
                                if(open[i1] == buy[i][i2]){
                                    System.out.print(open[i1]+"\t");
                                    view_RedCount++;
                                }
                            }
                        }
                        System.out.println();
                        //judge the blue-ball
                        System.out.print("The blue-ball winning numbers:");
                        if(open[6]==buy[i][6]){
                            System.out.print(open[6]);
                            view_BlueCount++;
                        }
                        System.out.println();
                        //judge the level of price
                        if(view_RedCount==6&&view_BlueCount==1){
                            System.out.println("Get the first price!!! The price is "+5000000*buy[i][7]);
                            view_Sum += 5000000 * buy[i][7];
                            view[0]++;
                        } else if (view_RedCount==6&&view_BlueCount==0) {
                            System.out.println("Get the second price!!! The price is "+500000*buy[i][7]);
                            view_Sum += 500000 * buy[i][7];
                            view[1]++;
                        }else if (view_RedCount==5&&view_BlueCount==1) {
                            System.out.println("Get the third price!!! The price is "+50000*buy[i][7]);
                            view_Sum += 50000 * buy[i][7];
                            view[2]++;
                        }else if (view_RedCount==5&&view_BlueCount==0 || view_RedCount==4&&view_BlueCount==1) {
                            System.out.println("Get the forth price!!! The price is "+200*buy[i][7]);
                            view_Sum += 200 * buy[i][7];
                            view[3]++;
                        }
                    }
                    System.out.println("------------------------In the end--------------------------");
                    if (view[0]!=0) {
                        System.out.println("In the end , you have win the first price " + view[0] + " times");
                    }
                    if (view[1]!=0) {
                        System.out.println("In the end , you have win the second price "+view[1]+" times");
                    }
                    if (view[2]!=0) {
                        System.out.println("In the end , you have win the third price "+view[2]+" times");
                    }
                    if (view[3]!=0) {
                        System.out.println("In the end , you have win the forth price "+view[3]+" times");
                    }
                    System.out.println("Totally get the bonus " + view_Sum);
                    System.out.println();
                    break;

case5&&default

case 5:
                    System.out.println("\nExit:");
                    System.out.println("About to exit system......");
                    System.out.println("ヾ(ToT)Bye~Bye~");
                    break o1;
                default:
                    System.out.println("\nPlease input a correct again!!![○・`Д´・ ○]\n");
                    break;

整体代码

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int menu = 0;

        int[][] buy = new int[200][8];
        int buy_RedCount = 0;
        int buy_RedTemp = 0;
        int buy_BlueTemp = 0;
        int buy_MultipleTemp = 0;
        int buy_Count = 0;
        char buy_Continue = 'n';
        boolean redSort_Flag = false;

        boolean open_Flag = false;
        Random open_Random = new Random();
        int[] open = new int[7];
        int open_RedTemp = 0;
        int open_RedCount = 0;

        int view_RedCount = 0;
        int view_BlueCount = 0;
        int[] view = {0, 0, 0, 0};
        int view_Multiple = 0;
        int view_Sum = 0;
        //Welcome
        System.out.println("\n****** ******* ******* ******* ******* ******* *******");
        System.out.println("Welcome to Two-Color ball!欢迎━(*`∀´*)ノ亻!");
        System.out.println("****** ******* ******* ******* ******* ******* *******");

        o1:
        do {
            System.out.println("Please select the function by numbers(*^▽^*)");
            System.out.println("1. Buy lottery;");
            System.out.println("2. View purchased numbers;");
            System.out.println("3. Open the price;;");
            System.out.println("4. View the Winners;");
            System.out.println("5. Exit;");
            menu = sc.nextInt();

            switch (menu) {
                case 1:
                    if (open_Flag){
                        System.out.println("\nJust able to buy lotteries before open price!!!\n");
                        break ;
                    }
                    System.out.println("\nBuy lottery:");
                    while (true) {
                        buy_RedCount = 0;
                        //red-ball
                        o2:
                        while (true) {
                            //input red-balls
                            System.out.println("Please input No." + (buy_Count + 1) + " lottery's red-ball's No." + (buy_RedCount + 1) + " number");
                            buy_RedTemp = sc.nextInt();
                            if (buy_RedTemp < 1 || buy_RedTemp > 31) {
                                System.out.println("\nPlease input the number between 1 and 31 again!!!\n");
                                continue;
                            } else {
                                for (int i = 0; i < buy_RedCount; i++) {
                                    if (buy_RedTemp == buy[buy_Count][i]) {
                                        System.out.println("\nCan't select the same ball!!!");
                                        System.out.println("Please input the number again!!!\n");
                                        continue o2;
                                    }
                                }
                                buy[buy_Count][buy_RedCount] = buy_RedTemp;
                                buy_RedCount++;
                                if (buy_RedCount == 6) {
                                    for (int i = 0; i < buy_RedCount - 1; i++) {
                                        for (int i1 = 0; i1 < buy_RedCount - 1 - i; i1++) {
                                            if (buy[buy_Count][i1] > buy[buy_Count][i1 + 1]) {
                                                buy_RedTemp = buy[buy_Count][i1];
                                                buy[buy_Count][i1] = buy[buy_Count][i1 + 1];
                                                buy[buy_Count][i1 + 1] = buy_RedTemp;
                                                redSort_Flag = true;
                                            }
                                        }
                                        if (!redSort_Flag) {
                                            break;
                                        }
                                    }
                                    break o2;
                                }
                            }

                        }

                        //blue-ball
                        while (true) {
                            System.out.println("Please input the blue-ball number:");
                            buy_BlueTemp = sc.nextInt();
                            if (buy_BlueTemp < 1 || buy_BlueTemp > 16) {
                                System.out.println("\nPlease input the number again!!!\n");
                                continue;
                            } else {
                                buy[buy_Count][buy_RedCount] = buy_BlueTemp;
                                break;
                            }
                        }

                        //multiple
                        while (true) {
                            System.out.println("Please input the multiple:");
                            buy_MultipleTemp = sc.nextInt();
                            if (buy_MultipleTemp < 2) {
                                System.out.println("\nPlease input the number more than 1!!!\n");
                                continue;
                            } else {
                                buy[buy_Count][buy_RedCount + 1] = buy_MultipleTemp;
                                break;
                            }
                        }

                        buy_Count++;
                        //continue
                        System.out.println("\nWhether what to buy a lottery again?(y/n)");
                        buy_Continue = sc.next().charAt(0);
                        if (buy_Continue == 'y' || buy_Continue == 'Y') {
                            System.out.println();
                            continue;
                        } else {
                            System.out.println("\nAbout exit purchase system...");
                            System.out.println("Good luck!\n");
                            break;
                        }


                    }
                    break;
                case 2:
                    System.out.println("\nView purchased numbers:");
                    for (int i = 0; i < buy_Count; i++) {
                        System.out.println("--------------------Lottery_" + (i + 1) + "------------------");
                        System.out.print("Red-Ball Numbers : ");
                        for (int j = 0; j < buy_RedCount; j++) {
                            System.out.print(buy[i][j] + "\t");
                        }
                        System.out.println();
                        System.out.print("Blue-Ball Numbers : ");
                        System.out.println(buy[i][buy_RedCount]);
                        System.out.print("Multiple Numbers : ");
                        System.out.println(buy[i][buy_RedCount + 1]);
                    }
                    System.out.println();
                    break;
                case 3:
                    //just able to open once
                    if(open_Flag){
                        System.out.println("\nJust able to open the price once!!!\n");
                        break ;
                    }
                    System.out.println("\nOpen the price:");
                    //set flag
                    open_Flag = true;
                    //generalize the red-ball
                    o3:
                    while(true) {
                        //use open_RedTemp rather than directly use array
                        open_RedTemp = open_Random.nextInt(31) + 1;
                        //remove the same random
                        for (int i = 0; i < open_RedCount; i++) {
                            if (open_RedTemp == open[i]) {
                                continue o3;
                            }
                        }
                        open[open_RedCount] = open_RedTemp;
                        open_RedCount++;
                        //exit red-ball generalize
                        if(open_RedCount==6){
                            break ;
                        }
                    }
                    //sort red-ball
                    for (int i = 0; i < 6 - 1; i++) {
                        for (int i1 = 0; i1 < 6 - 1 - i; i1++) {
                            if (open[i1]>open[i1+1]){
                                open_RedTemp = open[i1];
                                open[i1] = open[i1 + 1];
                                open[i1 + 1] = open_RedTemp;
                            }
                        }
                    }
                    //generalize blue-ball
                    open[6] = open_Random.nextInt(16) + 1;
                    System.out.println("The winning red-ball numbers:");
                    for (int i = 0; i < 6; i++) {
                        System.out.print(open[i]+"\t");
                    }
                    System.out.println();
                    System.out.println("The winning blue-ball numbers:");
                    System.out.print(open[6]);
                    System.out.println("\n");
                    break;
                case 4:
                    if (buy_Count==0){
                        System.out.println("\nPlease buy lotteries firstly!!!\n");
                        break ;
                    }
                    if (!open_Flag){
                        System.out.println("\nPlease open price firstly!!!\n");
                        break ;
                    }
                    System.out.println("\nView the Winners:");
                    for (int i = 0; i < buy_Count; i++) {
                        view_RedCount = 0;
                        view_BlueCount = 0;
                        //output the buy lotteries
                        System.out.println("--------------The No."+(i+1)+" lottery---------------");
                        System.out.print("The red-ball numbers:");
                        for (int i1 = 0; i1 < 6; i1++) {
                            System.out.print(buy[i][i1]+"\t");
                        }
                        System.out.println();
                        System.out.print("The blue-ball numbers:" + buy[i][6]);
                        System.out.println();
                        //judge the red-ball number and sum
                        System.out.print("The red-ball winning numbers:");
                        for (int i1 = 0; i1 < open.length-1; i1++) {
                            for (int i2 = 0; i2 < 6; i2++) {
                                if(open[i1] == buy[i][i2]){
                                    System.out.print(open[i1]+"\t");
                                    view_RedCount++;
                                }
                            }
                        }
                        System.out.println();
                        //judge the blue-ball
                        System.out.print("The blue-ball winning numbers:");
                        if(open[6]==buy[i][6]){
                            System.out.print(open[6]);
                            view_BlueCount++;
                        }
                        System.out.println();
                        //judge the level of price
                        if(view_RedCount==6&&view_BlueCount==1){
                            System.out.println("Get the first price!!! The price is "+5000000*buy[i][7]);
                            view_Sum += 5000000 * buy[i][7];
                            view[0]++;
                        } else if (view_RedCount==6&&view_BlueCount==0) {
                            System.out.println("Get the second price!!! The price is "+500000*buy[i][7]);
                            view_Sum += 500000 * buy[i][7];
                            view[1]++;
                        }else if (view_RedCount==5&&view_BlueCount==1) {
                            System.out.println("Get the third price!!! The price is "+50000*buy[i][7]);
                            view_Sum += 50000 * buy[i][7];
                            view[2]++;
                        }else if (view_RedCount==5&&view_BlueCount==0 || view_RedCount==4&&view_BlueCount==1) {
                            System.out.println("Get the forth price!!! The price is "+200*buy[i][7]);
                            view_Sum += 200 * buy[i][7];
                            view[3]++;
                        }
                    }
                    System.out.println("------------------------In the end--------------------------");
                    if (view[0]!=0) {
                        System.out.println("In the end , you have win the first price " + view[0] + " times");
                    }
                    if (view[1]!=0) {
                        System.out.println("In the end , you have win the second price "+view[1]+" times");
                    }
                    if (view[2]!=0) {
                        System.out.println("In the end , you have win the third price "+view[2]+" times");
                    }
                    if (view[3]!=0) {
                        System.out.println("In the end , you have win the forth price "+view[3]+" times");
                    }
                    System.out.println("Totally get the bonus " + view_Sum);
                    System.out.println();
                    break;
                case 5:
                    System.out.println("\nExit:");
                    System.out.println("About to exit system......");
                    System.out.println("ヾ(ToT)Bye~Bye~");
                    break o1;
                default:
                    System.out.println("\nPlease input a correct again!!![○・`Д´・ ○]\n");
                    break;
            }
        } while (true);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值