import java.util.Random; public class CoinToss { public static void main(String[] args) { Random r = new Random(); double x; int n = 0; x = r.nextDouble(); n++; while ( x < 0.5 ) { x = r.nextDouble(); n++; } System.out.println("# tosses = " + n ); } }