answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
earnstyle [38]
1 year ago
10

A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first s

tudent, denoted S1, opens every locker. Then the second student, S2, begins with the second locker, denoted L2, and closes every other locker (i.e. every even numbered locker). Student S3 begins with the third locker and changes every third locker (closes it if it was open, and opens it if it was closed). Student S4 begins with locker L4 and changes every fourth locker. StudentS5 starts with L5 and changes every fifth locker, and so on, until student S100 changes L100.After all the students have passed through the building and changed the lockers, which lockers areopen? Write a program to find your answer.(Hint: Use an array of 100 boolean elements. each of which indicates whether a locker is open (true) or closed (false). Initially, all lockers are closed.)
Computers and Technology
1 answer:
kati45 [8]1 year ago
5 0

Solution :

public class NewMain {  

   public_static void main_(String[] args) {  

       boolean[] _locker = new boolean_[101];  

       // to set all the locks to a false NOTE:  first locker is the number 0. Last locker is the 99.

       for (int_i=1;i<locker_length; i++)

       {

       locker[i] = false;

       }

       // first student opens all lockers.

       for (int i=1;i<locker.length; i++)        {

       locker[i] = true;

       }

       for(int S=2; S<locker.length; S++)

       {

          for(int k=S; k<locker.length; k=k+S)

          {

              if(locker[k]==false) locker[k] = true;

              else locker[k] = false;      

          }            

       }

       for(int S=1; S<locker.length; S++)

       {

           if (locker[S] == true) {

               System.out.println("Locker " + S + " Open");

           }

         /* else {

               System.out.println("Locker " + S + " Close");

           } */

       }

   }

}

You might be interested in
Problem 2 - K-Best Values - 30 points Find the k-best (i.e. largest) values in a set of data. Assume you are given a sequence of
masya89 [10]

Answer:

See explaination

Explanation:

/**KBestCounter.java**/

import java.util.ArrayList;

import java.util.List;

import java.util.PriorityQueue;

public class KBestCounter<T extends Comparable<? super T>>

{

PriorityQueue heap;

int k;

public KBestCounter(int k)

{

heap = new PriorityQueue < Integer > ();

this.k=k;

}

//Inserts an element into heap.

//also takes O(log k) worst time to insert an element

//into a heap of size k.

public void count(T x)

{

//Always the heap has not more than k elements

if(heap.size()<k)

{

heap.add(x);

}

//if already has k elements, then compare the new element

//with the minimum element. if the new element is greater than the

//Minimum element, remove the minimum element and insert the new element

//otherwise, don't insert the new element.

else if ( (x.compareTo((T) heap.peek()) > 0 ) && heap.size()==k)

{

heap.remove();

heap.add(x);

}

}

//Returns a list of the k largest elements( in descending order)

public List kbest()

{

List al = new ArrayList();

int heapSize=heap.size();

//runs O(k)

for(int i=0;i<heapSize;i++)

{

al.add(0,heap.poll());

}

//Restoring the the priority queue.

//runs in O(k log k) time

for(int j=0;j<al.size();j++) //repeats k times

{

heap.add(al.get(j)); //takes O(log k) in worst case

}

return al;

}

}

public class TestKBest

{

public static void main(String[] args)

{

int k = 5;

KBestCounter<Integer> counter = new KBestCounter<>(k);

System.out.println("Inserting 1,2,3.");

for(int i = 1; i<=3; i++)

counter.count(i);

System.out.println("5-best should be [3,2,1]: "+counter.kbest());

counter.count(2);

System.out.println("Inserting another 2.");

System.out.println("5-best should be [3,2,2,1]: "+counter.kbest());

System.out.println("Inserting 4..99.");

for (int i = 4; i < 100; i++)

counter.count(i);

System.out.println("5-best should be [99,98,97,96,95]: " + counter.kbest());

System.out.println("Inserting 100, 20, 101.");

counter.count(100);

counter.count(20);

counter.count(101);

System.out.println("5-best should be [101,100,99,98,97]: " + counter.kbest());

}

}

5 0
2 years ago
assume that name is a variable of type stirng that has been assigned a value write an expression whose value is the last charact
Snezhnost [94]

Answer:

The most straight forward way to do it: in general string are zero index based array of characters, so you need to get the length of the string, subtract one and that will be the last character, some expressions in concrete languages would be:

In Python:

name = "blair"

name[len(name) - 1]

In JavaScript:

name = "blair"

name[name.length - 1]

In C++:

#include <string>

string name = "blair";

name[name.length() - 1];

7 0
1 year ago
Wesley has to create a web banner to announce a “Back to School” sale by an online retailer. Which information should he determi
olganol [36]
I would say A :)))))))
4 0
2 years ago
Read 2 more answers
Explain what all sensory receptors have in common.
sp2606 [1]
The correct answer is that all receptors are considered to have the same feature, which is being a transducer.

Transducers change vitality starting with one form then onto the next. Generally, the receptor cells don't create an activation impulse by themselves. Rather, they create a progressively expanding potential, which triggers enactment of the afferent nerve fiber to which they are associated.
7 0
2 years ago
How do many corporations most likely manage the health and safety of their employees and the workplace?
s344n2d4d5 [400]

Answer:

The answer to this question is given below in the explanation section. However the correct option is only by following OSHA's rules and regulation.

Explanation:

Corporations most likely manage the health and safety of their emoployees and workplace only by following the OSHA's rules and regulations.

Because this is standard law that requires employers to provide their employees with working conditions that are free of known dangers. The OSH Act created the Occupational Safety and Health Administration (OSHA), which sets and enforces protective workplace safety and health standards for employees.

However, other options are not correct because these options do not cover the employees' protective workplace safety and health.

4 0
1 year ago
Other questions:
  • CAPTCHAs can be used as a form of signature to create a valid contract in e-commerce. True False
    6·2 answers
  • Sharon reads two different articles about avocados. The first article, in a weight loss magazine, claims that avocados are unhea
    10·2 answers
  • Suppose the algorithms used to implement the operations at layer k is changed. how does this impact services at layers k-1 and k
    10·1 answer
  • Which of the following statements is not true about proper tire care? a.If you see a wear bar across the width of the tread whil
    14·2 answers
  • Which Android application is used exclusively for sharing video content?
    12·2 answers
  • Annabeth has been using a public cloud to store and access her documents. Which drawback of a public cloud should she be aware o
    11·1 answer
  • Peter accumulated many photos from his visit to Wisconsin. He wants to upload these photos to a social networking site. Which fi
    12·1 answer
  • PYTHON QUESTION
    15·1 answer
  • Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", a
    7·1 answer
  • Jim is writing a program to calculate the wages of workers in a teddy bear factory.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!