zoukankan      html  css  js  c++  java
  • 双色球

    import java.util.Arrays;
    import java.util.Random;
    import java.util.Scanner;
    public class xun {
    public static void main(String[] args) {
    Random r=new Random();
    int[] userRedBall=new int[6];
    int userBlueBall=0;
    int[] sysRedBall=new int[6];
    int sysBlueBall=0;
    int redCount=0;
    int blueCount=0;
    //
    int[] redBall=new int[33];
    for(int i=0;i<redBall.length;i++) {
    redBall[i]=i+1;
    }
    System.out.println("1:机选,2:手动选择");
    Scanner input=new Scanner(System.in);
    boolean flag=true;
    while(flag) {
    int isAuto=input.nextInt();
    switch(isAuto) {
    case 1:
    computerSelection(redBall,userRedBall);
    userBlueBall=r.nextInt(16)+1;
    flag=false;
    break;
    case 2:
    System.out.println("请选择6个红球号码(1-33)");
    for(int i=0;i<userRedBall.length;i++) {
    userRedBall[i]=input.nextInt();
    }
    System.out.println("请选择1个红球号码(1-16)");
    userBlueBall=input.nextInt();
    flag=false;
    default:
    System.out.println("1:机选,2:手动选择");
    }
    }
    //系统结果
    computerSelection(redBall,sysRedBall);
    sysBlueBall=r.nextInt(16)+1;
    //统计结果
    for(int i=0; i<userRedBall.length;i++) {
    for(int j=0;j<sysRedBall.length-redCount;j++) {
    if(userRedBall[i]==sysRedBall[j]) {
    sysRedBall[j]=sysRedBall[sysRedBall.length-1-redCount];
    redCount++;
    }
    }
    }

    if(userBlueBall==sysBlueBall) {
    blueCount=1;
    }
    //
    if(blueCount==0 && redCount<=3) {
    System.out.println("no luck");
    }else if(blueCount==1 && redCount<3) {
    System.out.println("6");

    }else if((blueCount==1 && redCount==3)||(blueCount==0 && redCount==4)) {
    System.out.println("5");
    }else if((blueCount==1 && redCount==4)||(blueCount==0 && redCount==5)) {
    System.out.println("4");
    }else if(blueCount==1 && redCount==5) {
    System.out.println("3");
    }else if(blueCount==0 && redCount==6) {
    System.out.println("2");
    }else if(blueCount==1 && redCount==6) {
    System.out.println("1");
    }else {
    System.out.println("error");
    }
    Arrays.sort(sysRedBall);
    System.out.println(Arrays.toString(sysRedBall));
    Arrays.sort(userRedBall);
    System.out.println(userBlueBall);
    System.out.println(Arrays.toString(userRedBall));
    System.out.println(userBlueBall);
    }
    //ballCount是红球或篮球 redBall
    public static void computerSelection(int[] redBall,int[] useredBall) {
    Random r=new Random();
    int index=-1;
    for(int i=0;i<useredBall.length;i++) {
    index=r.nextInt(redBall.length-i);
    useredBall[i]=redBall[index];
    redBall[index]=redBall[redBall.length-1-i];
    }

    }
    }

  • 相关阅读:
    android debug:stack trace
    android binder IPC 通信中 asInterface 与 asBinder
    ubuntu WPS 对话框 使用GTK主题的方法
    init.rc
    make_ext4fs 文件权限控制
    百度地图api,点击标注,改变标注marker图标的链接地址
    dispatchEvent 自定义触发事件,常用于自定义鼠标事件或点击事件
    vue 中监听窗口发生变化,触发监听事件, window.onresize && window.addEventListener('resize',fn) ,window.onresize无效的处理方式
    chomre 控制台断点调试
    css,scss解决样式:表格的重叠边框
  • 原文地址:https://www.cnblogs.com/emma-zhu/p/9581043.html
Copyright © 2011-2022 走看看