Java random number usage example, probability statistics of coin tossing

From , 4 Years ago, written in Java, viewed 81 times.
URL https://pastebin.vip/view/86dba867
  1. public class coin{
  2. public static void main(String args[]){
  3. int n = 0;
  4. int m = 0;
  5. int len = 1000;
  6. int str[] = new int[len];
  7. for(int i = 0 ; i < len ; i ++){
  8. str[i] = ( int )(Math.random()*2);
  9. if(str[i] == 1 ){
  10. n = n + 1;
  11. }else{
  12. m = m + 1;
  13. }
  14. }
  15. System.out.println("正面朝上的次数:"+n);
  16. System.out.println("反面朝上的次数:"+m);
  17. }
  18. }
  19.  
  20.  
  21. //java/8168

Reply to "Java random number usage example, probability statistics of coin tossing"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website