摸珠子规则:
用一个袋子装了红绿蓝各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+"%");
}
}