// This program simulates flipping a coin. import java.util.*; class Flip { public static void main (String[] args) { Scanner scan = new Scanner (System.in); Random coin; coin = new Random(); int count = 0, heads = 0, tails = 0; int number_flips, flip_result; System.out.print ("Enter the number of flips: "); number_flips = scan.nextInt(); while (count < number_flips) { flip_result = Math.abs (coin.nextInt()) % 2; if (flip_result == 0) heads = heads + 1; else tails = tails + 1; count = count + 1; } System.out.println ("The number of heads is " + heads); System.out.println ("The number of tails is " + tails); } }