最近很火的摸珠子代码,求教~

摸珠子规则:

用一个袋子装了红绿蓝各8个珠子。玩家把手伸进口袋摸出12个珠子,数出不同颜色珠子个数,就能够获得相应的奖金。
比如摸出的12个珠子里,颜色最多的珠子有8个,颜色次多的珠子有4个,还有一种颜色没有,就叫840,玩家会获得100元!如果珠子个数是831,就能获得10元,如果是444,就能获得1元等等。

下面是运行的概率

先放运行截图:

在这里插入图片描述
因为感觉代码太臃肿就写了四种,没往下写
来看代码:

package TestList;
import java.util.*;
public class mozhuzi {
    public static void main(String[] args) {
        double num2=0;double num3=0;double num4=0;double num5=0;
        for (int x=0;x<100000;x++){
        int ax = 0; int bx = 0;   int cx = 0;
      ArrayList<Integer> a=new ArrayList<>();
      ArrayList<Integer> b=new ArrayList<>();
      ArrayList<Integer> c=new ArrayList<>();
      ArrayList<Integer> nums=new ArrayList<>();
        Random random=new Random();
//      添加元素
      for (int i=1;i<=24;i++){
            if (i<=8){
                a.add(i);
            }else if (i<=16 & i>8){
                b.add(i);
            }else {
                c.add(i);
            }
            nums.add(i);
      }
        for (int ab=1;ab<=12;ab++){
            int n=random.nextInt(nums.size());
            int num=nums.get(n);
            nums.remove(n);
            if (a.contains(num)){
                ax=ax+1;
            }if (b.contains(num)){
                bx=bx+1;
            }if (c.contains(num)) {
                cx=cx+1;
            }
        }
        System.out.println("a:"+ax);
        System.out.println("b:"+bx);
        System.out.println("c:"+cx);
   if (ax==3 & bx==4 & cx==5){
        num2=num2+1;
   }else if (ax==3 & bx==5 & cx==4){
       num2=num2+1;
   }else if (ax==4 & bx==3 & cx==5){
       num2=num2+1;
   }else if (ax==5 & bx==3 & cx==4){
       num2=num2+1;
   }else if (ax==4 & bx==5 & cx==3){
       num2=num2+1;
   }else if (ax==5 & bx==4 & cx==3){
       num2=num2+1;
   }
            if (ax==8 & bx==4 & cx==0){
                num3=num3+1;
            }else if (ax==8 & bx==0 & cx==4){
                num3=num3+1;
            }else if (ax==4 & bx==8 & cx==0){
                num3=num3+1;
            }else if (ax==0 & bx==8 & cx==4){
                num3=num3+1;
            }else if (ax==4 & bx==0 & cx==8){
                num3=num3+1;
            }else if (ax==0 & bx==4 & cx==8){
                num3=num3+1;
            }
                if (ax==8 & bx==3 & cx==1){
                    num4=num4+1;
                }else if (ax==8 & bx==1 & cx==3){
                    num4=num4+1;
                }else if (ax==1 & bx==8 & cx==3){
                    num4=num4+1;
                }else if (ax==3 & bx==8 & cx==1){
                    num4=num4+1;
                }else if (ax==3 & bx==1 & cx==8){
                    num4=num4+1;
                }else if (ax==1 & bx==3 & cx==8){
                    num4=num4+1;
                }
            if (ax==7 & bx==4 & cx==1){
                num5=num5+1;
            }else if (ax==7 & bx==1 & cx==4){
                num5=num5+1;
            }else if (ax==1 & bx==7 & cx==4){
                num5=num5+1;
            }else if (ax==4 & bx==7 & cx==1){
                num5=num5+1;
            }else if (ax==4 & bx==1 & cx==7){
                num5=num5+1;
            }else if (ax==1 & bx==4 & cx==7){
                num5=num5+1;
            }
        }
        System.out.println("3,4,5出现的概率为:"+num2/1000+"%");
        System.out.println("8,4,0出现的概率为:"+num3/1000+"%");
        System.out.println("8,3,1出现的概率为:"+num4/1000+"%");
        System.out.println("7,4,1出现的概率为:"+num5/1000+"%");
    }
}

用的太多if else了,有没有大佬帮我解决一下~
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜、空

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

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

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

打赏作者

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

抵扣说明:

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

余额充值