Results 1 to 10 of 10
  1. #1
    Geo
    Geo is offline New to Java
    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Question Problem to solve

    please I am quite new to java. Who can tell me how to go about this?

    A high school has 1000 students and 1000 lockers, one locker for each student. On the first day of school, the principal plays the following game: She asks the first student to open all the lockers. She then asks the second student to close all the even-numbered lockers. The third student is asked to check every third locker. If it is open, the student closes it; if it is closed, the student opens it. The fourth student is asked to check every fourth locker. If it is open, the student closes it; if it is closed, the student opens it. The remaining students continue this game. In general, the nth student checks every nth locker. If the locker is open, the student closes it; if it is closed, the student opens it. After all the students have taken their turns, some of the lockers are open and some are closed. Write a program that prompts the user to enter the number of lockers in a school. After the game is over, the program outputs the number of lockers and the locker numbers of the lockers that are open. Test runs your program for the following inputs: 1000, 5000, and 10000. Do you see any pattern developing for the locker numbers that are open in the output?

    (Hint: Consider locker number 100. This locker is visited by student numbers 1, 2, 4, 5, 10, 20, 25, 50, and 100. These are the positive divisors of 100. Similarly, locker number 30 is visited by student numbers 1, 2, 3, 5, 6, 10, 15, and 30. Note that if the number of positive divisors of a locker number is odd, then at the end of the game the locker is open. If the number of positive divisors of a locker number is even, then at the end of the game the locker is closed.)
    Last edited by Geo; 07-19-2012 at 01:09 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problem to solve

    Quote Originally Posted by Geo View Post
    please I am quite new to java. Who can give me a clue on how to solve this?
    Welcome to the Java-Forums.org!

    As for a clue, I would follow the instructions that were given by your instructor especially the hint. I also recommend that you have a look at "So, You Need to Write a Program but Don't Know How to Start" which can help you make sense out of these instructions.

    Other useful resources include your class notes and the Java tutorials, a very comprehensive set of quite helpful tutorials.

    Otherwise if you get stuck after reading the resource above, please post what you've tried and ask as specific a question as possible. Very general questions are impossible to answer other than giving general advice as I have done above.

    Also a suggestion for your next question here: please try to make your question heading more informative than "Problem to solve". Of course you have a problem otherwise you wouldn't be asking a question here. In the question heading try to summarize what your actual question is sort of like a newspaper headline summarizes the article beneath it.

  3. #3
    Geo
    Geo is offline New to Java
    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Default Re: Problem to solve

    Thanks a lot. But I still don't know how to start in solving this...can you go through it once small and see If you can atleast assist me?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problem to solve

    Quote Originally Posted by Geo View Post
    Thanks a lot. But I still don't know how to start in solving this...can you go through it once small and see If you can atleast assist me?
    But you still haven't yet told us specifically where you're stuck!

    If you've gone through the link that mentioned and followed every step in that link and are still totally lost, then I'm afraid that a forum won't be able to help you. You need to contact your instructor and get some one on one help.

    Otherwise if you want our help, you absolutely *must* ask a specific question. This means going through your protocol several times and asking very pointed questions on just what you don't understand. Listen, we're not going to write this code for you, but we'd be more than glad to try to clarify anything that confuses you and that helps *you* to write your code.

  5. #5
    Geo
    Geo is offline New to Java
    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Default Re: Problem to solve

    I didn't say you should write the program for me...Just an Idea how to start, but is alright...let me keep trying to figure it out... Thanks!

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Problem to solve

    Did you read the link to Patricia Shanahan's detailed suggestions?

    Point number one on that list is to understand the instructions. Do you understand them? What do you understand them to be asking you to do? (Look for the three sentences that actually ask you to do something.)

    Point number 4 is where I would start - even before writing a line of code. Get yourself a pencil and a piece of paper ruled up into squares representing a hundred or so lockers and actually play around with the problem.

  7. #7
    Geo
    Geo is offline New to Java
    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Default Re: Problem to solve

    I've read the instructions thoroughly... Thanks a lot for your suggestions. I truly appreciate.

  8. #8
    Geo
    Geo is offline New to Java
    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0

    Default Re: Problem to solve

    I'm still on it guys...

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem to solve

    The hint is a complete give away: first try to figure out if a number m is a true divisor of a number n; next try to figure out how many divisors exist for a number n; after a simple check, whether or not that number is even, you can solve your problem (add a loop over all the lockers).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Problem to solve

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. cant solve my problem .needs some help(C++):(y):
    By seongchog in forum New To Java
    Replies: 2
    Last Post: 12-03-2011, 08:49 PM
  2. Could someone help me to solve this problem...
    By Vinny in forum Java Software
    Replies: 1
    Last Post: 07-08-2009, 06:59 PM
  3. Help me to solve problem
    By mansoorhacker in forum Forum Guides
    Replies: 8
    Last Post: 01-24-2009, 06:29 PM
  4. Solve my Problem
    By kyo in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 02:22 PM
  5. Help me to solve problem
    By mansoorhacker in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 08:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •