关于网站开发的评审时间安排,绵阳 网站开发,邢台网站建设哪家公司好,wordpress访问后台主旨就是每个人出一个数#xff0c;目前限制两人#xff0c;之后考虑多人#xff0c;然后对其取差值#xff0c;获取到一个结果#xff0c;比对结果的奇偶数#xff0c;还可以看下两人出同一个数的概率#xff0c;反正概率上是一个比较稳定的。 当然自己想玩的活也可以做…主旨就是每个人出一个数目前限制两人之后考虑多人然后对其取差值获取到一个结果比对结果的奇偶数还可以看下两人出同一个数的概率反正概率上是一个比较稳定的。 当然自己想玩的活也可以做些小手脚比如奇数的结果固定的某些规则值放到偶数集合中。 反正小手脚就自己玩吧
现在只是加了一个简单的逻辑后续慢慢扩充吧有兴趣就把它弄成一个小网页放到网站上 import javax.xml.validation.Validator; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; import java.util.stream.Stream;
public class TwoPerson {
//创建一个随机数变量
static final Random random new Random();
//偶数
static final AtomicInteger evenCount new AtomicInteger();
//奇数
static final AtomicInteger oddCount new AtomicInteger();
//相同的次数概率
static final AtomicInteger sameNum new AtomicInteger();
//设定的 游戏次数
static final Long count 1000000L;
//创建集合,第n次相减的差,同时保留两人的数值
static final MapInteger,Person subPerson new HashMap();
public static void main(String[] args) {int person1 0;int person2 0;int sub 0;for (int i 0 ; i count ; i){person1 randomInt(0,9);person2 randomInt(0,9);sub person1-person2;if (sub 0){sub -sub;}Person person new Person(person1, person2,sub);subPerson.put(i,person);}for (int i: subPerson.keySet()) {Person person subPerson.get(i);if (person.getSub() % 2 0){evenCount.incrementAndGet();//得到结果之后就跳出循环不再执行之后的判断// continue; } if (person.getSub() % 2 0){ oddCount.incrementAndGet(); } if (person.getSub() 0){sameNum.incrementAndGet();}}//计算概率奇数的概率String odd probability(count, oddCount.longValue());System.out.println(奇数的概率:odd );//计算概率偶数的概率String even probability(count, evenCount.longValue());System.out.println(偶数的概率:even );//计算两人出同一个数的概率String same probability(count, sameNum.longValue());System.out.println(两人相同的概率same);}
//创建一个产生随机数的方法
private static int randomInt(int i,int j){//获取一个数据流拿到其中的一个值IntStream ints random.ints(i, j);return ints.iterator().nextInt();}
//计算概率
private static String probability(Long total,Long n){BigDecimal nB new BigDecimal(n);BigDecimal tB new BigDecimal(total);BigDecimal divide nB.divide(tB);return divide%;}}
//创建一个对象用于存储值 class Person{ private int person1;
private int person2;private int sub;public int getSub() {return sub;
}public void setSub(int sub) {this.sub sub;
}public int getPerson1() {return person1;
}public void setPerson1(int person1) {this.person1 person1;
}public int getPerson2() {return person2;
}public void setPerson2(int person2) {this.person2 person2;
}
public Person (int person1,int person2,int sub){this.person1 person1;this.person2 person2;this.sub sub;}}