fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.DecimalFormat;
  7. import java.util.Random;
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main(String[] args) {
  12. DecimalFormat df = new DecimalFormat("##.##%");
  13. double nbError, nbTest = 1000000;
  14. for (int charge = 1; charge < 11; charge++) {
  15. nbError = 0;
  16. for (int j = 0; j < nbTest; j++) {
  17. nbError += (isError(charge) ? 0 : 1);
  18. }
  19. System.out.println(charge + " -> " + df.format(nbError / nbTest));
  20. }
  21. }
  22.  
  23. private static boolean isError(int charge) {
  24. return new Random().nextInt(10) >= (11 - charge);
  25. }
  26. }
Success #stdin #stdout 0.55s 99424KB
stdin
Standard input is empty
stdout
1 -> 100%
2 -> 90.04%
3 -> 80.04%
4 -> 70.01%
5 -> 59.98%
6 -> 50.09%
7 -> 39.98%
8 -> 30%
9 -> 19.99%
10 -> 10%