Guest User

Untitled

a guest
Jan 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. public class Dice
  4. {
  5. Random random;
  6. public Dice()
  7. {
  8. random = new Random(); // get a random object
  9. }
  10. int roll()
  11. {
  12. int die1 = random.nextInt(6) + 1;// integer from 1 to 6,
  13. int die2 = random.nextInt(6) + 1;
  14. return die1+die2;
  15. }
  16.  
  17. public static void main(String args[])
  18. {
  19. // a test method
  20. Dice dice = new Dice();
  21. int snakeEyes = 0;
  22. for(int i = 1; i <= 1000; i ++)
  23. if (dice.roll() == 2)
  24. snakeEyes++;
  25. System.out.println("Number of Snake eyes in 1000 rolls: "+ snakeEyes);
  26. }
  27. }
Add Comment
Please, Sign In to add comment