编写一个程序模拟扔硬币的结果
import java.util.Random;public class Coin {
public static void main(String[] args) {
Random rand = new Random();
int x = 0;
int y = 0;
for(int j = 0 ; j < 1000000; j++) {
int i = rand.nextInt(2);
//System.out.println(i);
if (i==1) {
x++;
} else {
y++;
}
}
System.out.println("x="+x);
System.out.println("y="+y);
System.out.println((float)x/y);
}
}