Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- public class Dice
- {
- Random random;
- public Dice()
- {
- random = new Random(); // get a random object
- }
- int roll()
- {
- int die1 = random.nextInt(6) + 1;// integer from 1 to 6,
- int die2 = random.nextInt(6) + 1;
- return die1+die2;
- }
- public static void main(String args[])
- {
- // a test method
- Dice dice = new Dice();
- int snakeEyes = 0;
- for(int i = 1; i <= 1000; i ++)
- if (dice.roll() == 2)
- snakeEyes++;
- System.out.println("Number of Snake eyes in 1000 rolls: "+ snakeEyes);
- }
- }
Add Comment
Please, Sign In to add comment