import java.util.Random; public class AvgHeight { public static void main(String[] args) { Random r = new Random(); int i, h, sum; sum = 0; for (i = 0; i < 1000; i++ ) { h = 1; while ( r.nextDouble() < 0.5 ) h++; System.out.println("height = " + h ); sum += h; } System.out.println("Avg. height = " + (double)sum/1000 ); } }