您的位置:首页 > 其它

模拟投掷硬币,出现正反面的次数(…

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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: