Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active December 25, 2015 17:09
Show Gist options
  • Select an option

  • Save imryan/7011308 to your computer and use it in GitHub Desktop.

Select an option

Save imryan/7011308 to your computer and use it in GitHub Desktop.
Rolls dice.
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