模拟一个双色球程序(机选或自选)

package HomeWork05;

import java.util.Scanner;

public class ShuangSeQiu {

    //初始界面
    public static int Welcome(){
        System.out.println("--------------------------欢迎进入双色球机选系统(本次奖金500万)--------------------------");
        System.out.println("                      1.机选双色球                      2.自选双色球");
        Scanner input = new Scanner(System.in);
        int select = input.nextInt();
        return select;
    }


    //生成红色球
    public static int[] ProduceRed(){
        int[] Red = new int[6];
        int temp;
        //产生不重复的双色球
        for(int i = 0;i < 6;i++){
            Red[i] = (int)(Math.random()*33)+1;
            for(int j = 0;j < i;j++){
                if(Red[i] == Red[j]){
                    i--;
                    break;
                }
            }
        }
        /*
        System.out.println("生成的不重复的红色球");
        for (int i = 0;i < 6;i++)
            System.out.print(Red[i]+"\t");

         */
        //对生成的红色球进行排序
        for(int i = 0;i < Red.length - 1;i++){
            for (int j = 0;j < Red.length - 1 - i;j++){
                if(Red[j] > Red[j+1]){
                    temp = Red[j];
                    Red[j] = Red[j+1];
                    Red[j+1] = temp;
                }
            }
        }
        return Red;
    }


    //生成蓝色球
    public static int ProduceBlue(){
        int blue = 0;
        blue = (int)(Math.random()*16)+1;
        return blue;
    }


    //选取中奖蓝色球与红色球
    // 调用ProduceRed()和ProduceBlue()使得生成完整中奖序列
    public static int[] Select(){
        //前六个是红色球,第七个是蓝色球
        int[] array = new int[7];
        int[] array1 = ProduceRed();
        //生成红色球
        for(int i = 0;i < 6;i++)
            array[i] = array1[i];
        //生成蓝色球
        array[6]= ProduceBlue();
        return array;
    }

    //选取用户蓝色球与红色球
    // 调用ProduceRed()和ProduceBlue()使得生成完整中奖序列
    public static int[] XuanHao(){
        int[] array2 = new int[6];
        //将自动生成的号码放入array2
        array2 = Select();
        int[] array5 = new int[7];
        array2 = Select();
        int[] array3 = new int[6];
        System.out.println("为您生成的红色球");
        for (int i = 0; i < 6; i++){
            System.out.print(array2[i]+ "\t");
            array5[i] = array2[i];
        }
        System.out.println();
        System.out.println("为您生成的蓝色球:");
        array5[6] = ProduceBlue();
        System.out.println(array5[6]);
        return array5;
    }

    //
    public static int[] JiXuan(){
        int[] array3 = new int[6];
        array3 = Select();
        int[] array4 = new int[6];
        array4 = Select();
        int[] array6 = new int[7];


        System.out.println();
        System.out.println("中奖红色球");
        for (int i = 0; i < 6; i++){
            System.out.print(array3[i] + "\t");
            array6[i] = array3[i];
        }
        System.out.println();
        System.out.println("中奖蓝色球");
        array6[6] = ProduceBlue();
        System.out.println(array6[6]);
        return array6;

    }

    //生成中了几等奖
    public static void KaiJiang(int[] a1,int[] a2){
        int count = 0;
        for(int i = 0;i < a1.length - 1;i++){
            for(int j = 0 ;j < a2.length - 1;j++){
                if(a1[i] == a2[j]){
                    count++;
                }
            }
        }
        if(count == 6 && a1[6]==a2[6])
            System.out.println("一等奖");
        else if(((count == 6) && (a1[6] !=a2[6])))
            System.out.println("二等奖");
        else if((a1[6]==a2[6] && count == 5))
            System.out.println("三等奖");
        else if((a1[6]==a2[6] && count == 4)||(count == 5) && (a1[6] !=a2[6]))
            System.out.println("四等奖");
        else if((a1[6]==a2[6] && count == 3)||(count == 4) && (a1[6] !=a2[6]))
            System.out.println("五等奖");
        else if (a1[6]==a2[6])
            System.out.println("六等奖");
        else
            System.out.println("未中奖");

    }

    //自选
    public static int[] ShouXuan(){
        System.out.println("请输入6个红色球号码与1个蓝色球号码");
        Scanner input = new Scanner(System.in);
        int nums = input.nextInt();
        int[] n = new int[7];
        for(int i = 0;i < n.length;i++){
            n[i] = nums % 10;
            nums = nums / 10;
        }
        return n;
    }


    public static void main(String[] args) {
        int select = Welcome();
        int[] array2 = new int[7];
        if(select == 1){
                KaiJiang(XuanHao(),JiXuan());
        }
        else
            KaiJiang(ShouXuan(),XuanHao());

    }
}

在这里插入图片描述
在这里插入图片描述收获:
从根本上杜绝了自己想靠买彩票发财的想法

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值