Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago