Last active
December 25, 2015 17:09
-
-
Save imryan/7011308 to your computer and use it in GitHub Desktop.
Rolls dice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Dice | |
| { | |
| public static void main (String[] args) | |
| { | |
| // Call the roll method | |
| rollDice(); | |
| } | |
| public static void rollDice() | |
| { | |
| // Create random generator & assign values | |
| Random generator = new Random(); | |
| int randomSide1 = generator.nextInt(7); | |
| int randomSide2 = generator.nextInt(7); | |
| while (randomSide1 == 0 || randomSide2 == 0) | |
| { | |
| randomSide1 = generator.nextInt(7); | |
| randomSide2 = generator.nextInt(7); | |
| } | |
| // Output results | |
| System.out.println("Die 1: " + randomSide1); | |
| System.out.println("Die 2: " + randomSide2); | |
| System.out.println("All die: " + (randomSide1 + randomSide2)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment