日期:2014-05-20 浏览次数:20705 次
package com.test;
/**
* Created by kehan628
* Date: 2013-9-22
* Time: 09:50:49
*/
public class Shuangseqiu {
public static void main(String[] args) {
show(new int[]{15,17,18,21,29,32,13}); //参数为中奖号码
}
/**
* 生成5000个随机号,并判断中奖金额,是否盈利
* @param jiang
*/
private static void show(int[] jiang){
int sum=0;
for(int i=0;i<5000;i++){
int[] red = getRed();
StringBuffer sb=new StringBuffer("红号");
for (int b = 0; b < 6; b++) {
if(red[b]<10)
sb.append(" 0"+red[b]);
else
sb.append(" "+red[b]);
}
int blue = (int) (Math.random() * 16 + 1);
if(blue<10)
sb.append(" 蓝号 0"+ blue);
else
sb.append(" 蓝号 "+ blue);
int money=zhongjiang(jiang,new int[]{red[0],red[1],red[2],red[3],red[4],red[5],blue});
sb.append(" 中奖金额: " + money);
if(money>=3050){
System.out.println(sb.toString());
sum += money * 0.8;
}else
sum += money;
}
System.out.println(sum);
}
/**
* 获取 6个红色号码
* @return
*/
private static int[] getRed(){
int[] red = new int[6];
for (int i = 0; i < 6; i++) {
red[i] = getNum(i,red);
}
return paixu(red);
}
/**
* 获取一个随机号码
* @param num 随机号码的序号
* @param red 随机的一个红色号码
* @return
*/
private static int getNum(int num,int[] red){
int rs = (int) (Math.random() * 33) + 1;
for(int i = 0; i < num; i++){
//System.out.println("判断重复!数字:"+num+"--数值:"+rs+"--比较ID:"+i+"==比较值:"+red[i] );
if(rs==red[i]){
rs = getNum(num,red);
break;
}
}
return rs;
}
/**
* 对所选号码进行排序
* @param red 将要排序的红色号码
* @return
*/
public static int[] paixu(int[] red){
int temp;
for (int i = 0; i < 6; i++) {
for (int j = i + 1; j < 6; j++) {
if (red[i] > red[j]) {