发新话题

编写一个程序 模拟扔硬币的结果

编写一个程序 模拟扔硬币的结果
觉得下面这样做没有实现真正的模拟 请各位帮忙思考下
import java.util.Random;

public class Practice7 {
	public static void main(String[] args) {
		Random rand = new Random();
		int coin = rand.nextInt();
		if(coin % 2 == 0)
			System.out.println("heads");
		else System.out.println("tails");		
	}
}
----------------------http://michelecindy.javaeye.com



编辑 回复 快速回复 TOP
int coin = rand.nextInt()%2;
编辑 回复 快速回复 TOP
发新话题