Workbook 5.10
From the Java Bootcamp Resources
, launch 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!
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.
Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer
Feedback Summary
4.7
43 students
5
91%
4
2%
3
0%
2
0%
1
7%
Written Reviews
There are no written reviews yet.