Results 1 to 10 of 10
Thread: Problem to solve
 07192012, 12:57 AM #1New to Java
 Join Date
 Jul 2012
 Posts
 5
 Rep Power
 0
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 evennumbered 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; 07192012 at 01:09 AM.

Re: Problem to solve
Welcome to the JavaForums.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.
 07192012, 06:25 AM #3New to Java
 Join Date
 Jul 2012
 Posts
 5
 Rep Power
 0
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?

Re: Problem to solve
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.
 07192012, 07:14 AM #5New to Java
 Join Date
 Jul 2012
 Posts
 5
 Rep Power
 0
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!
 07192012, 08:11 AM #6Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,565
 Rep Power
 12
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.
 07192012, 08:49 AM #7New to Java
 Join Date
 Jul 2012
 Posts
 5
 Rep Power
 0
Re: Problem to solve
I've read the instructions thoroughly... Thanks a lot for your suggestions. I truly appreciate.
 07192012, 09:25 AM #8New to Java
 Join Date
 Jul 2012
 Posts
 5
 Rep Power
 0
Re: Problem to solve
I'm still on it guys...
 07192012, 10:04 AM #9
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 12,999
 Blog Entries
 7
 Rep Power
 19
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,
Joscenosillicaphobia: the fear for an empty beer glass
 07202012, 09:38 PM #10
Re: Problem to solve
Please go through the Forum Rules  particularly the third paragraph.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads

cant solve my problem .needs some help(C++):(y):
By seongchog in forum New To JavaReplies: 2Last Post: 12032011, 08:49 PM 
Could someone help me to solve this problem...
By Vinny in forum Java SoftwareReplies: 1Last Post: 07082009, 06:59 PM 
Help me to solve problem
By mansoorhacker in forum Forum GuidesReplies: 8Last Post: 01242009, 06:29 PM 
Solve my Problem
By kyo in forum New To JavaReplies: 1Last Post: 12162008, 02:22 PM 
Help me to solve problem
By mansoorhacker in forum New To JavaReplies: 3Last Post: 11132008, 08:15 AM
Bookmarks