/* Percentile : Find the percentile of x with respect to a Gaussian (normal) * distribution with a given mean and standard deviation. * * Parke Godfrey 2009-Sept-29 */ import java.io.PrintStream; import java.util.Scanner; import type.lib.ToolBox; import org.apache.commons.math.MathException; import org.apache.commons.math.distribution.NormalDistributionImpl; public class Percentile { public static void main(String[] args) throws MathException { PrintStream output = System.out; Scanner input = new Scanner(System.in); final double MEAN = 174.0; //Ave Canadian male height. final double STD_DEV = 8.4; output.print("Enter the height (cm)..."); int height = input.nextInt(); ToolBox.crash(height < 0, "Problem!"); NormalDistributionImpl gaussian = new NormalDistributionImpl(MEAN, STD_DEV); double percentile = gaussian.cumulativeProbability(height); output.printf("For the height %dcm, " + "the percentile is %5.1f%%.%n", height, percentile * 100); } }