全球视点!模拟一个双色球程序(机选或自选)

2022-09-16 15:33:36来源:互联网  


【资料图】

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());    }}


收获:
从根本上杜绝了自己想靠买彩票发财的想法

相关阅读

精彩推荐

相关词

推荐阅读