Java Bootcamp – Workbooks and Challenges
)}

Workbook 5.10

From Java Bootcamp Resources -> Module 1 -> 5. Loops, open Workbook 5.10.

Roll doubles


The user must keep rolling dice until they roll doubles!

Task 1


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)
 *
 */

Task 2


Call the rollDice() function twice, and store the values in variables: dice1 and dice2. Then, print each dice value as follows:

System.out.println("Dice 1: " + dice1);

System.out.println("Dice 2: " + dice2 + "\n");

Task 3


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.

Task 4


After they roll doubles, print:

You rolled doubles!

Good Luck!


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.