鱼虾蟹游戏测试同时买几个的时候赚钱的几率最高?
结论:同时买5种的时候,60%的几率能赢钱!!
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* 鱼虾蟹
* 1:鱼,2:虾,3:蟹,4:金钱, 5:葫芦,6:鸡
* @author Ho
*
*/
public class Game {
private static Random random = new Random();
private static String buyWhat = "12356";
public static void main(String[] args) {
int sum = 0;
for(int i=0; i<10000; i++){
//获取随机结果
List<String> resultList = getRandomResult();
int temp = 0;
StringBuffer sb = new StringBuffer();
for(int j=0; j<3; j++){
String str = resultList.get(j);
sb.append(str);
if(buyWhat.indexOf(str) != -1){ //含有买的动物
temp ++;
}
}
//计算本轮输赢,减掉本钱,加盈利的钱
int count = 0 - buyWhat.length() + temp * 2 ;
if(count >= 0){
System.out.println(sb.toString()+"->赢钱->"+count);
}else{
System.out.println(sb.toString()+"->输钱->"+count);
}
//计算最终结果
sum = sum + count ;
}
System.out.println("最终结果:"+sum);
}
/**
* 返回随机结果
* @return
*/
public static List<String> getRandomResult(){
ArrayList<String> list = new ArrayList<String>();
for(int i=0; i<3; i++){
list.add(random.nextInt(6)+1+"");
}
return list;
}
}