fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static double[] w(int s, int f)
  11. {
  12. double n = s + f, z = 1.96, x = Math.pow(z, 2), p = s + x / 2, d = z * Math.sqrt(s * f / n + x / 4), m = 1 / (n + x);
  13. return new double[]
  14. { m * (p - d), m * (p + d) };
  15. }
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. String[] inputs =
  19. { "0, 1", "1, 0", "1, 1", "1, 10", "10, 1", "10, 90", "90, 10", "25, 75", "75, 25", "50, 50", "0, 100", "100, 0" };
  20.  
  21. for (String input : inputs)
  22. {
  23. int s = Integer.parseInt(input.split(", ")[0]);
  24. int f = Integer.parseInt(input.split(", ")[1]);
  25. double[] r = w(s, f);
  26. System.out.println(s + ", " + f + " => " + r[0] + ", " + r[1]);
  27. }
  28. }
  29. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
0, 1 => 0.0, 0.7934567085261071
1, 0 => 0.20654329147389294, 1.0
1, 1 => 0.09452865480086611, 0.905471345199134
1, 10 => 0.016231752262825982, 0.3773646254862038
10, 1 => 0.6226353745137962, 0.9837682477371741
10, 90 => 0.05522854161313612, 0.1743673043676654
90, 10 => 0.8256326956323345, 0.9447714583868639
25, 75 => 0.17545094003724265, 0.3430464637007583
75, 25 => 0.6569535362992417, 0.8245490599627573
50, 50 => 0.40382982859014716, 0.5961701714098528
0, 100 => 0.0, 0.03699480747600191
100, 0 => 0.9630051925239981, 1.0