Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Solution {
  4.  
  5. public static void main(String args[]){
  6. long a = 0;
  7. Random rand = new Random();
  8. for(int i = 0; i < 10000; i++){
  9. int[] arr = new int[4];
  10. arr[0] = rand.nextInt(6) + 1;
  11. arr[1] = rand.nextInt(6) + 1;
  12. arr[2] = rand.nextInt(6) + 1;
  13. arr[3] = rand.nextInt(6) + 1;
  14. Arrays.sort(arr);
  15. while(arr[1] < 3){
  16. arr[1] = rand.nextInt(6) + 1;
  17. }
  18. while(arr[2] < 3){
  19. arr[2] = rand.nextInt(6) + 1;
  20. }
  21. while(arr[3] < 3){
  22. arr[3] = rand.nextInt(6) + 1;
  23. }
  24. a += arr[1] + arr[2] + arr[3];
  25. }
  26. System.out.println(a/10000.0);
  27. long b = 0;
  28. for(int i = 0; i < 10000; i++){
  29. int[] arr = new int[4];
  30. arr[0] = rand.nextInt(6) + 1;
  31. arr[1] = rand.nextInt(6) + 1;
  32. arr[2] = rand.nextInt(6) + 1;
  33. arr[3] = rand.nextInt(6) + 1;
  34. while(arr[0] < 3){
  35. arr[0] = rand.nextInt(6) + 1;
  36. }
  37. while(arr[1] < 3){
  38. arr[1] = rand.nextInt(6) + 1;
  39. }
  40. while(arr[2] < 3){
  41. arr[2] = rand.nextInt(6) + 1;
  42. }
  43. while(arr[3] < 3){
  44. arr[3] = rand.nextInt(6) + 1;
  45. }
  46. Arrays.sort(arr);
  47. b += arr[1] + arr[2] + arr[3];
  48. }
  49. System.out.println(b/10000.0);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement