Advertisement
brilliant_moves

Dice.java

Sep 7th, 2012
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.71 KB | None | 0 0
  1. public class Dice {
  2.  
  3.     /**
  4.     *   Program:    Dice.java
  5.     *   Purpose:    Yahoo! Answers, Dice simulation
  6.     *   Creator:    Chris Clarke
  7.     *   Created:    23.04.2012
  8.     */
  9.  
  10.     public static int rollDice() {
  11.         int Min = 1;
  12.         int Max = 6;
  13.         int result = Min + (int)(Math.random() * Max);
  14.         return result;
  15.     }
  16.  
  17.     public static void main (String[] args) {
  18.         int dice1;
  19.         int dice2;
  20.         int total = 0;
  21.  
  22.         do {
  23.             dice1 = rollDice();
  24.             total += dice1;
  25.             dice2 = rollDice();
  26.             total += dice2;
  27.             System.out.println( "Dice One = "+dice1+", Dice Two = "+dice2);
  28.             if (dice1 == dice2) {
  29.                 System.out.println( "Dice are equal: have another throw");
  30.             }
  31.         } while (dice1 == dice2);
  32.  
  33.         System.out.println( "Total = " + total);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement