Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Dice {
- /**
- * Program: Dice.java
- * Purpose: Yahoo! Answers, Dice simulation
- * Creator: Chris Clarke
- * Created: 23.04.2012
- */
- public static int rollDice() {
- int Min = 1;
- int Max = 6;
- int result = Min + (int)(Math.random() * Max);
- return result;
- }
- public static void main (String[] args) {
- int dice1;
- int dice2;
- int total = 0;
- do {
- dice1 = rollDice();
- total += dice1;
- dice2 = rollDice();
- total += dice2;
- System.out.println( "Dice One = "+dice1+", Dice Two = "+dice2);
- if (dice1 == dice2) {
- System.out.println( "Dice are equal: have another throw");
- }
- } while (dice1 == dice2);
- System.out.println( "Total = " + total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement