 Let's do the locker puzzle by hand to see what's going on behind the scenes. Not with 100 lockers, that would take way too long, but with 10 lockers. Here are the lockers numbered 1 through 10. They all start out as closed. I'll use a minus sign to represent closed and a check mark to represent open. Student number 1 comes in and starts at locker number 1 and then switches all open lockers to closed and all closed lockers to open. Locker 1 is closed, they open it. Proceed to locker 2, which is closed, they open it. Since all the lockers are closed, they'll all be open when student 1 finishes. Student number 2 comes in, starts at locker number 2, and switches the status of every other locker. That means they'll close lockers 2, 4, 6, 8, and 10. Let's stop for a moment and analyze what just happened there. We started with the locker number that's the same as the student number, and switched its status. Then we added 2, which is the student number, 2 plus 2 is 4, to get to the next locker that we had to examine. We switched its status and then added the student number again, 4 plus 2 is 6, and so on to examine all those lockers. Let's look at student 3. Student 3 starts at locker 3 and closes that locker. 3 plus 3 is every third locker, 3 plus 3 is 6, opens locker 6, 6 plus 3, the student number, is 9, and closes locker number 9. Here comes student number 4. Student number 4 starts at locker number 4 and opens it. 4 plus 4 is 8, and that gets opened. Student number 5 starts at locker number 5 and closes it. 5 plus 5 is 10, and opens it. Student 6 starts at locker 6 and closes it. Every sixth locker would be locker 12, which is beyond our limit of 10, and student 6 is finished. If we had 100 lockers, they would go on to lockers 12, 18, 24, and so on. Same with student number 7. Starts at locker 7 and closes it, and they're finished. Student number 8 starts at locker number 8 and closes it. Student 9 starts at locker number 9 and opens it, and for our example, finally student number 10 starts at locker 10 and closes it. Let's put those all in a row. We have open, closed, closed, open, closed, closed, closed, open, and closed. The open lockers are numbers 1, 4, and 9. Hint, do you see a pattern emerging here? When we translate this to Java, we're going to have a nested loop. Our outer loop is going to process the students, students 1 through 10, and for each student that comes in, they're going to start at their locker number and go to the end. That's the inner loop. The outer loop is for the students. The inner loop is for the lockers that they have to examine. And here's the pseudocode. We're going to have an array of booleans called isOpen, and it's going to be 100 long. We'll have to set all the lockers to be closed. We'll have a for loop that runs from 1 to 100 inclusive. The problem here is that our indexes for the isOpen array go from 0 to 99. That means when we actually access the array, we have to subtract 1 so that we don't go out of bounds. Then we'll have our student numbers go from 1 to 100 inclusive. Start at the locker number corresponding to that student, and in this case, I'm using a while loop rather than a for loop to examine the lockers for that student. You can do it with a for loop, but the pseudocode is a bit clearer when I use a while. Once all the students have done their thing, I can go through all the lockers and see if they're open, and if they are, I'll print the locker number. There's the pseudocode. The other question we have is how do we switch a boolean variable representing our locker from open to closed and back again? Here's a similar example to give you some ideas. Let's say we have a boolean called light is on that's either true for on or false for off. Here's one way that we can do it. We can say if light is on equals true, then we'll set it to false. Otherwise, it must be false and we'll set it to true. This works, but it's not good coding practice. First, light is on is already a boolean. Instead of comparing it to true, we can directly ask if light is on, which will be a true or false value. That's better. But there's even a better solution, the not operator. Consider this. What is not true? That's false. What is not false? That's true. That means I can replace this entire if statement with a single statement saying light is on becomes not light is on. When light is on is true, not true is false, which will be assigned to light is on. When light is on is false, not light is on will become true and that will become the new value.