Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A high school has 1000 students and 1000 lockers, one locker foreach student. On

ID: 3614464 • Letter: A

Question

A high school has 1000 students and 1000 lockers, one locker foreach student. On the first day of school, the principal plays thefollowing game: She asks the first student to open all the lockers.She then asks the second student to close all the even-numberedlockers. The third student is asked to check every third locker. Ifit is open, the student closes it; if it is closed, the studentopen it. The fourth student is asked to check every fourth locker.If it is open, the student closes it; if it is closed, the studentopens it. The remaining students continue this game. In general,the nth student closed, the student opens it. After all thestudents have taken their turns, some of the lockers are open andsome are closed. Write a program that prompts the user to enter thenumber of lockers in a school. After the game is over, the programoutputs the number of lockers and the locker numbers of the lockersare open. Test run your program for the following: 1000, 5000,10000. Do you see any pattern developing for the locker numbersthat are open in the output?

Explanation / Answer

please rate - thanks import java.util.Scanner; public class Lockers { public static void main(String []args) { int students; int[]locker = new int[10000]; inti,j,open=0;             //using the variable will make things easier later Scanner keyboard = new Scanner(System.in); System.out.println("Enter the number of students"); students = keyboard.nextInt(); for ( i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote