java编程思想练习题-第3章练习7-随机数

题目:编写一个程序,模拟扔硬币的结果。

import java.util.*; 
public class test {
	
	public static void main(String[] args) {
		Random rand = new Random();
		int coin = rand.nextInt();
		if(coin % 2 == 0) System.out.println("正面");
		else  System.out.println("背面");		
	}


}

 随机数是以System.currentMillionSeconds为种子计算出来的。

猜你喜欢

转载自buptchj.iteye.com/blog/2247422