# Need help to understand this question.

• September 24th, 2014, 07:45 PM
Rods
Need help to understand this question.
Hey all,
I got assigned this problem for my homework. I am having so hard time to understand what does she wants me to do in this program.
Anybody who can help me in this?
Here is the problem:
A run is a sequence of adjacent repeated values.
write a program that generates a sequence of 20 random die tosses
(between 1 and 6) in an array and prints the die values, marking
the 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 algorithm:
set a boolean variable inRun to false
For each valid index i in the array
ifinRun
if value[i] is different from the preceding value
print )
inRun=false
if not inRun
if value[i] is the same as the following value
print (
inRun=true
print value[i]
ifinRun
print )
• September 24th, 2014, 07:55 PM
Norm
Re: Need help to understand this question.
The pseudo code makes sense to me.
Which steps are you having problems with?
• September 24th, 2014, 09:25 PM
Rods
Re: Need help to understand this question.
First thing that I am having trouble with is do I have to put random class?

--- Update ---

First thing that I am having trouble with is do I have to put random class?
• September 24th, 2014, 09:32 PM
Norm
Re: Need help to understand this question.
Does that mean you understand what the modulus operator does and how to use it?

Quote:

write a program that generates a sequence of 20 random die tosses
That will require a random number generator.

I'd recommend you wait on that part of the code until you have the scanning part finished.
Hardcode an array for testing the scan part and work on that. It will be easier to debug the logic if the data stays the same. When the scanning code works, change the array and test it again, and again.
When you think it works, then worry about how to randomly fill the array.
• September 24th, 2014, 09:43 PM
Rods
Re: Need help to understand this question.
So, basically First I have to use Scanner and ask user for input?
Once I get input by user, in next step I can use random class and then compare both arrays?
• September 25th, 2014, 04:26 AM
GregBrannon
Re: Need help to understand this question.
Take it a step at a time. Successful, efficient problem solving involves breaking a large problem down into manageable steps, and that's what the pseudo-code has attempted to do for you. It's good that you have the whole design in mind, but your concern about step 6 is preventing you from accomplishing steps 1 through 5. Once you've done steps 1 through 5, step 6 may not seem that formidable. Start at the beginning, accomplish and test each step before moving to the next, come here for help anytime you need to complete a step, but post your code (correctly) so that we can see what you need help with.
• September 25th, 2014, 06:48 AM
Norm
Re: Need help to understand this question.
Quote:

have to use Scanner and ask user for input
Sorry, i meant scanning as the process of going over the contents of the array item by item (scanning them) to find runs. I don't see where any user input is required.