模拟投掷硬币,出现正反面的次数(…
2017-01-10 15:31
141 查看
public class E0407
{
public static void main(String args[])
{
int x=0,y=0;
int n=Integer.parseInt(args[0]);
for(int i=1;i<=n;i++)
{
int a=(int)(Math.random()*2);
//int a=r.nextInt[0,1];
if(a==0)
{
x++;
}
else
{
y++;
}
}
System.out.println("出现正面的次数为"+x);
System.out.println("出现反面的次数为"+y);
}
}
{
public static void main(String args[])
{
int x=0,y=0;
int n=Integer.parseInt(args[0]);
for(int i=1;i<=n;i++)
{
int a=(int)(Math.random()*2);
//int a=r.nextInt[0,1];
if(a==0)
{
x++;
}
else
{
y++;
}
}
System.out.println("出现正面的次数为"+x);
System.out.println("出现反面的次数为"+y);
}
}
相关文章推荐
- 模拟投掷骰子,一至六点出现的次数…
- CCF计算机软件能力认证模拟试题-出现次数最多的数(Java参考答案学习记录)
- 投掷100次掷子计算每个数出现的次数 C#源码案例 附第二种简单解法
- Excel 中统计某个项目出现的次数,以及模拟SQL的Group by效果
- CCF认证模拟之出现次数最多的数
- 模拟实现atoi和itoa以及100G 的IP地址求出现次数最多的前K个IP
- 抛硬币第一次出现连续两个正面的期望次数
- CCF计算机软件能力认证模拟试题-出现次数最多的数(Java参考答案学习记录)
- Random产生随机数模拟投掷硬币
- ACM--模拟--气球出现次数--HDOJ 1004--Let the Balloon Rise--水
- 投掷6000次 1-6 出现的次数(已有3种解法)
- 骰子每个面都出现需要投掷的次数期望 又 优惠券问题
- JavaScript中模拟java的map键值统计一段英文中各个单词出现的次数
- 其实人家是模拟。。。(思路)(统计cow出现的次数)
- 找出数组中出现次数超过一半的数
- 求一个字符串中出现另一子字符串的次数
- SQL 查询一个字段所有的之出现次数大于等于2的条数
- 读取一个.txt文件并计数每个单词出现的次数
- 在hadoop上进行编写mapreduce程序,统计关键词在text出现次数
- Python实现计算一段文本中每个单词出现的次数