Question: A run is a sequence of adjacent repeated values. Write a program that prompts the user to enter a sequence lengthn, then creates an object
Arunis a sequence of adjacent repeated values. Write a program that prompts the user to enter a sequence lengthn, then creates an object to generate a sequence ofnrandom die tosses in an array and a method toprint the die values, marking runs by including them in parentheses, like this:
1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 3 1
Use the following pseudocode:
Set a boolean value inRun to false. For each index i in the array { If inRun { if(values[i] is different from the preceding value{ print ) inRun = false } } if not inRun { if values[i] is the same as the following value{ print ( inRun = true } } print values[i] } If inRun, print )
See Die.java on page 279 for how to generate a random roll of a die. Find the source code in Files -> Text Examples -> bigjavaExamples -> Ch06 -> section_9_1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
