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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!