Java Bootcamp Resources ->
Module 1 ->
5. Loops, open Workbook 5.10.
The user must keep rolling dice until they roll doubles!
First, make a function that returns a random number between 1 and 6.
/** * Function name: rollDice -- rolls a dice between 1 and 6 * @return randomNumber (int) * */
rollDice() function twice, and store the values in variables:
dice2. Then, print each dice value as follows:
System.out.println("Dice 1: " + dice1);
System.out.println("Dice 2: " + dice2 + "\n");
Set up a loop that keeps running while the two dice aren't the same. During each run, re-roll the dice and print both values.
After they roll doubles, print:
You rolled doubles!