标签:col string void class tin int hello random new
下学期学java了,先拿C++程序改编一下练练手
package helloworld; import java.util.Random; public class hello { public static void main(String[] args) { for(int i = 0; i < n; ++i){ Random x1 = new Random(); Random x2 = new Random(); int r1 = x1.nextInt(2); int r2 = x2.nextInt(2); if(r1 == girl && r2 == girl) g2++; if(r1 == girl || r2 == girl) g1++; } System.out.println(g2 * 1.0 / g1); } static int girl = 0, boy = 1; static int g1 = 0; static int g2 = 0; static int n = 10000; }
一个家庭两个孩子,已知一个是女孩,另一个是女孩的概率是?Java
标签:col string void class tin int hello random new
原文地址:https://www.cnblogs.com/MasterYan576356467/p/11182649.html