码迷,mamicode.com
首页 > 其他好文 > 详细

HW4.44

时间:2016-08-19 20:35:17      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 1 public class Solution
 2 {
 3     public static void main(String[] args)
 4     {
 5         double randX;
 6         double randY;
 7         int hitCount = 0;
 8 
 9         for(int i = 0; i <= 1000000; i++)
10         {
11             randX = Math.random() * 200 - 100;
12             randY = Math.random() * 200 - 100;
13             
14             if(randX < 0)
15                 hitCount++;
16             if(randX > 0 && randY > 0 && randY < randX)
17                 hitCount++;
18         }
19 
20         System.out.println("The hit chance is " + hitCount * 1.0 / 1000000);
21     }
22 }

 

HW4.44

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5788730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!