private boolean countRandom(int a){
if(a<0 && a>100)
return false;
int random1 = randomInt(100);
return random1<=a;
}private void lab4(){
//初始化拾取物品,怪物有4个物品,概率分别是80,60,40,20
int[] goods ={80,60,40,20};
boolean[] results = new boolean[goods.length];
for(int i=0;i<goods.length;i++){
results[i] = countRandom(goods[i]);
}
System.out.println(Arrays.toString(results));
}个人感觉,这么写还是不好.但又不知道有什么其他的方法,搜不到有用的,所以请教下各位,有什么思路没谢谢附:一道题
a ,b ,c三个人打枪
a打中的概率为1/3
b打中的概率为1/2
c打中的概率为 1
 a 先打 c, 如果 c 中枪,则 b 打 a
如果 c 活着,b 再打 c ,这时如果 c 中枪,则 a打b
如果c仍然活着,则 c 打 b,(此时b一定死),a 再打 c
如果c仍然活着, 则 c 打 a (此时a一定死)
请教 a、b、c各自的死亡概率 和存活概率

解决方案 »

  1.   

    if(a<0 && a>100)
    这个条件如何才能达到啊= =
      

  2.   

    if(a<0 && a>100)
    强啊~
      

  3.   

    a ,b ,c三个人打枪
    a打中的概率为1/3
    b打中的概率为1/2
    c打中的概率为 1
     a 先打 c, 如果 c 中枪,则 b 打 a
    如果 c 活着,b 再打 c ,这时如果 c 中枪,则 a打b
    如果c仍然活着,则 c 打 b,(此时b一定死),a 再打 c
    如果c仍然活着, 则 c 打 a (此时a一定死)
      有意思、
      

  4.   


    a是概率值.countRandom(int a),是随机数小于概率值则true比如 10%
    a = 10;random = 15;
    falserandom = 5;
    true
      

  5.   

    不是不是……
    你仔细看下你一开始直接判断的return false的条件………………
      

  6.   


    写错了 应该是if(a<0 || a>100)
    不过不影响结果,a就没有符合条件的.嘎嘎
      

  7.   

    a、b、c的存活概率分别为11/18,5/9,2/9。
    a、b、c的死亡概率分别为7/18,4/9,7/9。
      

  8.   

    import java.util.Random;
    public class shoot {
    public static final int STATCOUNT = 10000;

    public static void main(String[] args) {
    int a = 0;
    int b = 0;
    int c = 0;
    int adied = 0;
    int alive = 0;
    int bdied = 0;
    int blive = 0;
    int cdied = 0;
    int clive = 0;
    Random random = new Random();
    for(int i = 0;i < STATCOUNT;i++){
    a = random.nextInt(3);
    if(a == 0){         //a 打c ,打中
    b = random.nextInt(2);
    if(b == 0){
    adied ++;
    blive ++;
    cdied ++;
    }else{
    alive ++;
    blive ++;
    cdied ++;
    }
    }

    if(a > 0){       //a打c,没打中
    b = random.nextInt(2);
    if(b == 0){   //b打c,打中
    a = random.nextInt(3);
    if(a == 0){         //a 打b,打中
    alive ++;
    bdied ++;
    cdied ++;
    }else{
    alive ++;
    blive ++;
    cdied ++;
    }
    }else{//b打c,没打中,然后c打b,一定打中。
    a = random.nextInt(3);
    if(a == 0){         //a 打c,打中
    alive ++;
    bdied ++;
    cdied ++;
    }else{      //a 打c,没打中。再c打a,a必死
    adied ++;
    bdied ++;
    clive ++;
    }
    }

    }
    }

    System.out.printf("a活的概率为: %f\n",(double)alive/STATCOUNT);
    System.out.printf("a死的概率为: %f\n",(double)adied/STATCOUNT);

    System.out.printf("b活的概率为: %f\n",(double)blive/STATCOUNT);
    System.out.printf("b死的概率为: %f\n",(double)bdied/STATCOUNT);

    System.out.printf("c活的概率为: %f\n",(double)clive/STATCOUNT);
    System.out.printf("c死的概率为: %f\n",(double)cdied/STATCOUNT);

    }}
    结果:
    a活的概率为: 0.613900
    a死的概率为: 0.386100
    b活的概率为: 0.546100
    b死的概率为: 0.453900
    c活的概率为: 0.221700
    c死的概率为: 0.778300