Last active
August 29, 2015 14:18
-
-
Save khatchad/7657a9cbb9b9628febad to your computer and use it in GitHub Desktop.
This program simulates the rolling of dice.
This file contains 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.Scanner; | |
import java.util.Random; | |
/** | |
* This program simulates the rolling of dice. | |
*/ | |
public class RollDice | |
{ | |
public static void main(String[] args) | |
{ | |
String again = "y"; // To control the loop | |
// Create a Scanner object to read keyboard input. | |
Scanner keyboard = new Scanner(System.in); | |
// Create a Random object to generate random numbers. | |
Random rand = new Random(); | |
// Simulate rolling the dice. | |
while (again.equalsIgnoreCase("y")) | |
{ | |
System.out.println("Rolling the dice..."); | |
int die1 = rand.nextInt(6) + 1; | |
int die2 = rand.nextInt(6) + 1; | |
System.out.println("Their values are:"); | |
System.out.println(die1 + " " + die2); | |
System.out.print("Roll them again (y = yes)? "); | |
again = keyboard.nextLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment