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]
3 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
What is the main function of the output on a computer or what is it use for? ​
choli [55]

Answer:

It is used to transfer data

Explanation:

An output used on a computer is used for transferring your data from your device to another by any user

3 0
2 years ago
Read 2 more answers
What is the following file format called? inv_nbr, inv_name, inv_cost 876521,battery,45.00
kiruha [24]

The  following file format of  inv_nbr, inv_name, inv_cost is called delimited format.

<h3>What is a delimited file in Excel?</h3>

The term "Delimited" is known to be a term that connote a form of  an  TXT file that tends to make use of tabs or an  CSV file that uses commas to  be able to separate and group your data.

Note also that a  delimited file is seen as a form of a given sequential file that is made up of column delimiters.

Therefore, The  following file format of  inv_nbr, inv_name, inv_cost is called delimited format.

Learn more about text format from

brainly.com/question/16397886

#SPJ1

Multiple Choice

fixed-width format

extensible markup

delimited format

hypertext format

6 0
1 year ago
You are the IT administrator for a small corporate network. You have installed the Windows Server 2016 operating system on a ser
Elan Coil [88]

Answer:

In this lab, you perform the following tasks:

• On Disk 1, create a mirrored volume of the System (C:) volume to add fault tolerance.

• Using Disk 2, Disk 3, and Disk 4, create a RAID 5 volume that provides both fault tolerance and improved performance using the following settings:

o Volume size: 2 TB

o Drive letter: R

o Format: NTFS

o Volume label: Data

Complete this lab as follows:

1. Mirror an existing volume as follows:

a. Right-click Start and select Disk Management.

b. Click OK to initialize new disks.

c. Maximize the Disk Management window to better view the volumes.

d. Right-click the System (C:) volume and select Add Mirror.

e. Select Disk 1 that will be used for the mirrored copy.

f. Select Add Mirror.

g. Click Yes to convert the basic disk to a dynamic disk.

2. Create a RAID 5 volume as follows:

a. In Disk Management, right-click a disk with free space and select New RAID 5 Volume.

b. Click Next.

c. Under Available, holding down the Ctrl key, select Disk 3 and Disk 4 to be part of the new volume with Disk 2.

d. Select Add.

e. Click Next.

f. From the drive letter drop-down dialog, select R; then click Next.

g. Make sure that NTFS is selected as the file system.

h. In the Volume label field, enter Data.

i. Select Next.

j. Click Finish to create the volume.

k. Click Yes to convert the basic disk to a dynamic disk.

Explanation:

5 0
3 years ago
A program is required to three (3) numbers. calculate and print their total
podryga [215]

A program that is required to three (3) numbers. calculate and print their total is given below:

<h3>The Program</h3>

import java.util.Scanner;

public class SumAndAverage {

public static void main(String[ ] args) {

System.out.println("Enter three numbers - ");

// Accepting and finding sum of numbers.

int sum = 0;

Scanner sc = new Scanner(System.in);

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

sum += sc.nextInt( );

// Printing sum and average.

System.out.println("Sum - " + sum);

System.out.println("Average - " + (sum / 3f));

}

}

The output would request three different numbers, then add them up, and display the output of the sum and then display or print their total


Read more about programming here:

brainly.com/question/23275071

#SPJ1

5 0
1 year ago
Ignore this it a temporary note for me: SPSstudents
Westkost [7]

Answer:

okk

Explanation:

3 0
1 year ago
Other questions:
  • Using Python
    14·1 answer
  • In 2–3 sentences, describe how you would insert a table into a word-processing document.
    9·2 answers
  • 18. Using the same formatting elements and designs across slides in a presentation is important to develop?
    5·1 answer
  • You get a BRAINLIEST if you help me ASAP!
    11·2 answers
  • What additional features on your router would you implement if you were setting up a small wired and wireless network
    5·1 answer
  • What is a collection of computer programs that administer the hardware and software of a computer so that they work properly?
    7·1 answer
  • One condition for deadlocks is the circular-wait condition. One way to ensure that this condition never holds is to impose a tot
    12·2 answers
  • Juan has performed a search on his inbox and would like to ensure the results only include those items with attachments which co
    14·2 answers
  • Each student has a record on a file consisting of the following data: Student last name, Student ID (numeric), GPA (a decimal nu
    7·1 answer
  • Find the name of the professor with the maximum percentage of students that failed his course.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!