Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need help to understand this question.

  1. #1
    Junior Member Rods's Avatar
    Join Date
    Sep 2014
    Location
    New York
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb 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 )


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help to understand this question.

    The pseudo code makes sense to me.
    Which steps are you having problems with?
    List the step and ask a question about your problem with it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member Rods's Avatar
    Join Date
    Sep 2014
    Location
    New York
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help to understand this question.

    Does that mean you understand what the modulus operator does and how to use it?

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member Rods's Avatar
    Join Date
    Sep 2014
    Location
    New York
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default 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.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help to understand this question.

    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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. can someone please help me understand this question.
    By Tattva in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 10th, 2014, 01:12 PM
  2. Please Help me to understand
    By Theillusion in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 17th, 2013, 03:09 AM
  3. Please help to Understand x=++x+ + +x+x++
    By rayan2004 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: December 2nd, 2012, 07:47 PM
  4. [SOLVED] Quick Question: Did I understand these directions correctly?
    By msinc210 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 3rd, 2012, 03:03 PM
  5. Replies: 0
    Last Post: December 12th, 2011, 03:17 PM