
public class FlipCoins {

	public static void main(String[] args) {
		//constants
		final int TAILS = 0;
		final int HEADS = 1;
		//number of trials
		final int TRIALS = 1000000;
		
		//count how many
		int tailsCount = 0;
		int headsCount = 0;
		
		//repeat the trials
		for(int i = 1; i <= TRIALS; i += 1) {
			//flip the coin
			int flip = (int)(Math.random()*2);
			//check result
			if(flip == TAILS) {
				tailsCount++;
			}
			else {
				//HEADS is the only other option
				headsCount++;
			} //end else
		}//end for
		
		System.out.printf("%d heads and %d tails out %d flips.\n", 
				headsCount, tailsCount, TRIALS);
	}

}
