标签:
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 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5788730.html