We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicclassSolution{publicstaticvoidmain(String[]args){doublemean=20;doublestdDeviation=2;doublex1=19.5,x2=22;doubleresult1=probability(mean,stdDeviation,x1);doubleprobLe20=0.5;// le mean == ge mean == 50%doubleresult2=probability(mean,stdDeviation,x2)-probLe20;System.out.println(round(result1));System.out.println(round(result2));}staticdoubleprobability(doublemean,doublestdDeviation,doublex){finaldoublez=calcZ(mean,stdDeviation,x);return1-(1+erf(z))/2;}staticdoublecalcZ(doublemean,doublestdDeviation,doublex){return(mean-x)/(stdDeviation*Math.sqrt(2));}staticdoubleerf(doublez){doublesum=0;for(intn=0;n<11;n++){doublet=z/(2*n+1);for(inti=1;i<=n;i++)t*=-z*z/i;sum+=t;}return2/Math.sqrt(Math.PI)*sum;}staticdoubleround(doublev){returnMath.round(v*1000)*1d/1000;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 5: Normal Distribution I
You are viewing a single comment's thread. Return to all comments →