Question
CO SCI 141 Programming In Java The lockers that are opened have an interesting property, what is it? public class Exercise07_23 { public static void
CO SCI 141 Programming In Java
The lockers that are opened have an interesting property, what is it?
public class Exercise07_23 { public static void main(String[] args) {
boolean[] lockers = new boolean[100];
for (int student = 1; student <= 100; student++) { shuffle(lockers, student); } display(lockers); }
public static void shuffle(boolean[] lockersOpenState, int start) {
int nextLocker = start; for (int i = start - 1; i < lockersOpenState.length; i += nextLocker) { lockersOpenState[i] = !lockersOpenState[i];
} }
public static void display(boolean[] lockers) {
int lockerCount = 0; for (int i = 0; i < lockers.length; i++) {
if (lockers[i]) { System.out.printf("L%d ", i+1); lockerCount++; if (lockerCount % 10 == 0) System.out.println(""); }
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started