A high school has 1000 students and 1000 lockers,one locker for each student,On
ID: 3640751 • Letter: A
Question
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 ask the second student to close all the even numbered lockers, The thrd student is asked to check every third locker . if it is open ,the student closes it.; if it is closed,the student will open it. The fourth student is ask to check every fourth locker, same thing like the third student. The remaining student will continue the game. In general, the nth student checks every nth locker. 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 the lockers and the locker numbers that are open. Test run your program for the following inputs: 1000, 5000, 10000.Explanation / Answer
PS: Please rate the answer Save as Locker.java (Irrelevant but still: The opened doors are the numbers which are squares between 1 and the number of students) import java.util.Scanner; public class Locker{ public static boolean[] locker; public Locker(int len){ locker = new boolean[len]; } public static void openLocker(){ for(int i = 1; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.