1answer.
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
12345 [234]
4 years ago
6

There are N bulbs numbered from 1 to N, arranged in a row. The first bulb is plugged into the power socket and each successive b

ulb is connected to the previous one. (Second bulb to first, third to second) Initially, all the bulbs are turned off. A moment K (for K from 0 to N-1), the A[K]-th bulb is turned on. A bulbs shines if it is one and all the previous bulbs are turned on too. Write a function in java that given an Array A of N different integers from 1 to N, returns the number of moments for which every turned on bulb shines.
Computers and Technology
1 answer:
Ksivusya [100]3 years ago
3 0

Answer:

The code is given below with appropriate comments

Explanation:

// TestSolution class implementation

import java.util.Arrays;

public class TestSolution

{

  // solution function implementation

  public static int solution(int[] arr)

  {

      // declare the local variables

      int i, j, count = 0;

      boolean shines;

     

      // use the nested loops to count the number of moments for which every turned on bulb shines

      for (i = 0; i < arr.length; i++)

      {

          shines = true;

          for (j = i + 1; j < arr.length && shines; j++)

          {

              if (arr[i] > arr[j])

                  shines = false;

          }

          if (shines)

              count++;

      }

      // return the number of moments for which every turned on bulb shines

      return count;

     

  } // end of solution function

 

  // start main function

  public static void main(String[] args)

  {

      // create three arrays named A, B, and C

      int[] A = {2, 1, 3, 5, 4};

      int[] B = {2, 3, 4, 1, 5};

      int[] C = {1, 3, 4, 2, 5};

     

      // generate a random number N within the range range[1..100000]

      int N = 1 + (int)(Math.random() * 100000);

     

      // create an array named D of size N

      int[] D = new int[N];

     

      // fill the array D with the distinct random numbers within the range [1..N]

      int i = 0;

      while(i < N)

      {

          int num = 1 + (int)(Math.random() * N);          

          boolean found = false;

          for(int j = 0; j < i && !found; j++)

          {

              if(D[j] == num)

                  found = true;

          }

         

          if(!found)

          {

              D[i] = num;

              i++;

          }

      }          

     

      // print the elements and number of moments of the arrays A, B, and C

      System.out.println("Array A: " + Arrays.toString(A) + " and Moments: " + solution(A));

      System.out.println("Array B: " + Arrays.toString(B) + " and Moments: " + solution(B));

      System.out.println("Array C: " + Arrays.toString(C) + " and Moments: " + solution(C));

     

      // print the size and number of moments of the array D

      System.out.println("Size(N) of Array D: " + N + " and Moments: " + solution(D));

     

  } // end of main function

} // end of TestSolution class

You might be interested in
Which font attribute would be most appropriate to make a papers heading stand out?
eimsori [14]

If you want your heading to pop out I would go for bold Becuase it shows the letters darker and bigger which would make the heading the center of attention.

7 0
3 years ago
Read 2 more answers
You are researching RAM for a computer you are building for a friend who will be using the system as a home office server for he
AlexFokin [52]

Answer:

ECC memory

Explanation:

According to my research on information technology, I can say that based on the information provided within the question the best type of RAM for this situation would be ECC memory (RAM). This abbreviation refers to Error-Correcting-Code, this memory can detect and correct many common types of errors, and is used mainly for servers or when sensitive data is involved where errors and data corruption cannot be allowed to happen under any circumstance.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

3 0
4 years ago
Your company leases a very fast internet connection and pays for it based on usage. You have been asked by the company president
azamat

Answer:

c. Install a proxy server

Explanation:

In computing a proxy server is implemented as a middle 'man' between the user and the internet. It will hence behave as a gateway that will seperate users from the websites that they browse. The major importance of a proxy server is enforcing security, however it can also act as a web filter allowing organizations to restrict access to certain websites. So when an organization or a school wishes to prevent access to certain sites a proxy server will be implemented, in the question scenario this web filter feature can be used to save cost associated with visiting sites not relevant to the organization's objectives

7 0
3 years ago
A software developer would utilize a(n) ________ to detail a compilation of hardware and software components to create a framewo
sweet [91]

A software developer would utilize an architectural design to detail a compilation of hardware and software components to create a framework for software development.

The term architectural design denotes the oftware architecture while the term non-architectural design denotes the detailed design. The architect draws the line between these two designs.

6 0
3 years ago
A recently promoted employee at your company has called you because they attempted to log in to their computer several times wit
oksano4ka [1.4K]

Answer:

The user's account is blocked due to several unsuccessful login attempts.

Explanation:

Any device having a password security has a property of blocking the account or device in use after noticing several unsuccessful attempts of login.

So as a precautionary measure when the software notices such activity it blocks the access to that account so that any intruder might not be able to enter the account premises.

Same is the case with the employee who was trying to access his own account but due the expired password he made several attempts but couldn't log in. The software took it as an intruder and blocked the account.

The employee after requesting for password reset again tried to login but the account was blocked so he could not be able to access it again.

7 0
3 years ago
Other questions:
  • What is computer virus?
    8·1 answer
  • Here is a Test Code segment:
    13·1 answer
  • Write the method public static doublell quizAverages (double (1 scores). which takes a 2D array of doubles that represent quiz s
    11·1 answer
  • 100 POINTS + BRAINLYEST TO FIRST PERSON THAT IS CORRECT!!! Tomika wants to create a cell style for her workbook and share it wit
    13·2 answers
  • Suppose that we have a set of activities to schedule among a large number of lecture halls, where any activity can take place in
    12·1 answer
  • How does human error relate to security risks
    5·1 answer
  • True or false? LearnSmart (the "smart flash card assignments") really gets your competitive spirit in gear by allowing you to se
    8·1 answer
  • What server role provides IEEE 802.1X authentication features? (Points : 5) File services
    10·1 answer
  • As you are discussing marketing with a client, you try to explain how individuals find sites. Which tool will you explain as the
    8·1 answer
  • Spreadsheets are sometimes credited with legitimizing the personal computer as a business tool. Why do you think they had such a
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!