• + 0 comments
    public class Solution {
    
        public static void main(String[] args) {
            double mean = 70;
            double stdDeviation = 10;
            double x1 = 80, x2 = 60;
            
            double result1 = 1 - probability(mean, stdDeviation, x1);
            double result3 = probability(mean, stdDeviation, x2);
            double result2 = 1 - result3;
            
            System.out.println(round(result1*100));
            System.out.println(round(result2*100));
            System.out.println(round(result3*100));
        }
        
        public static double probability(double mean, double stdDeviation, double x) {
            final double z = calcZ(mean, stdDeviation, x);
            return 1 - (1 + erf(z)) / 2;
        }
    
        public static double calcZ(double mean, double stdDeviation, double x) {
            return (mean - x) / (stdDeviation * Math.sqrt(2));
        }
    
        public static double erf(double z) {
            double sum = 0;
            for (int n = 0; n < 11; n++) {
                double sfsfsf = z / (2 * n + 1);
                for (int i = 1; i <= n; i++) sfsfsf *= -z * z / i;
                sum += sfsfsf;
            }
            return 2 / Math.sqrt(Math.PI) * sum;
        }
    
        static double round(double v) {
            return Math.round(v * 100)*1d/100;
        }
    }