Sunday, October 23, 2011

Flipping a Coin

public class Flip  
{
    public static void main(String[] args)  
    { 
        Math.random() returns a value between 0.0 and 1.0
        if (Math.random() < 0.5)
        System.out.println("Heads");
        else  
        System.out.println("Tails");
    }
}

No comments:

Post a Comment