luyantl 发表于 2018-9-20 23:49:11

java_Random(]

import java.util.*;
public class RandomCoin
{
        public static void main(String[] args)
        {
                Random coin=new Random();
                int c1=0;
                int        c2=0;
                for(int x=0;x<1000;x++)
                {
                        if (coin.nextInt(2)==0)
                        {
                                c1=c1+1;
                        }
                        else
                        {
                                c2=c2+1;
                        }
                }
                System.out.println("正面c1==>"+c1);
                System.out.println("反面c2==>"+c2);
        }
}
页: [1]
查看完整版本: java_Random(]