
/** FlipCoinDemoFor, modified from the original while loop version. 
 *  Tue Feb 28 2006
 */
public class FlipCoinDemoFor
{
    public static void main( String[] args )
    {
	// We use a constant instead of a magic number 
        final int NUM_FLIPS = 1000000;
        int heads = 0;
        int tails = 0;
        int limit = NUM_FLIPS; 
 
	// Move initialization and increment here. Keep conditional
	// the same.
        for (int i = 1;i <= limit ;i++) 
        {
            double result = Math.random();
            
            if (result <= 0.5) {
                        tails++;
                } else if (result > .5) { 
                        heads++;
                }
        }
	// To be on the safe side, also print out the sum of
	// heads+tails to make sure we got our loop termination
	// condition correct!
        System.out.println("Heads: "+heads + " tails " +tails+" total "+ (heads+tails));
    }
}
