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
MrRissso [65]
4 years ago
13

The numbers should be added to the merged array in an alternating pattern: first from list 1, then from list 2, then list 1 agai

n, etc. If a number in one of the arrays already appears in the merged array, then it should be ignored, and the program should alternate to the other list again. For example, if the first list begins 1 2 3 10, and the second begins 3 4 5 8, then the merged list would begin 1 3 2 4 5 10 8.
Engineering
1 answer:
Vinvika [58]4 years ago
4 0

Answer:

According to the complete question, the code below gives the solution to the problem in Java with appropriate comments

Explanation:

import java.util.Scanner;

import java.lang.Math;

class Main {

  public static void main(String[] args) {

      int length = 0;

      boolean lengthCheck = true;

      Scanner scan = new Scanner(System.in);

      while (lengthCheck == true)

      {

          System.out.println("Enter an array length (must be 10 or greater):");

          length = scan.nextInt();

          if (length >= 10)

          {

              lengthCheck = false;

          }

      }

      int[] firstArray = new int[length];

      int[] secondArray = new int[length];

      System.out.print("\nFirst Array: ");

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

      {

          firstArray[i] = (int) (Math.random() * 100) + 1;

          System.out.print(firstArray[i] + " ");

      }

      System.out.print("\n\nSecond Array: ");

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

      {

          secondArray[i] = (int) (Math.random() * 100) + 1;

          System.out.print(secondArray[i] + " ");

      }

      System.out.println("\n");

     

     

/*

* A boolean array of length 100 to track list of number we have already added to merge list

*/

      boolean[] isAdded = new boolean[100];

      int[] merge = new int[(firstArray.length + secondArray.length)];

     

      int j=0;

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

      {

          if(!isAdded[firstArray[i] - 1]) {

              merge[j] = firstArray[i];

              j++;

              isAdded[firstArray[i] - 1] = true;

          }

         

          if(!isAdded[secondArray[i] - 1]) {

              merge[j] = secondArray[i];

              j++;

              isAdded[secondArray[i] - 1] = true;

          }

         

      }

     

      System.out.print("Merged Array: ");

     

      for (int i = 0; i < 2*length && merge[i] != 0; i++)

      {

          System.out.print(merge[i] + " ");

      }

      System.out.println("\n");

     

  }

}

You might be interested in
The primary difference between integrated/concurrent engineering development and functional/sequential development is: Integrate
gogolik [260]

Answer:

Integrated development spends more money up front to order to save money in later stages.

Explanation:

The primary difference between integrated/concurrent engineering development and functional/sequential development is: Integrated development spends more money up front to order to save money in later stages.

Cost of integrated development is higher in the initial stages where setup has be made and proper training and education of employees are required and once it is done. It will save money in later stages.

7 0
4 years ago
Hidiesjcfkesudfmjhtredcvbnm,lkjhgfdsuytrkduefkvke
Grace [21]

Answer:

THANKS FOR THE POINTS!!!!!!!

3 0
3 years ago
Read 2 more answers
A) Fix any errors to get the following program to run in your environment. B) Document each line of code with comments and descr
Bingel [31]

Answer:

Answer is explained below

Explanation:

<u>Part A -: </u>

<u> </u>

<u>Error statement -: </u>

/*

prog.cpp: In function ‘void p(const int*, int)’:

prog.cpp:7:15: error: assignment of read-only location ‘* list’

list[0] = 100;

*/

There is one error in the code in following part

void p( const int list[], int arraySize)

{

list[0] = 100;

}

you are passing list as constant but changing it inside the function that is not allowed. if you pass any argument as const then you can't change it inside the function. so remove const from function argument solve the error.

<u>Part B -: </u>

change made

void p( int list[], int arraySize)

{

list[0] = 100;

}

<u>Executable fully commented code -: </u>

#include <iostream> // importing the iostream library

using namespace std;

void m(int, int []); // Function declearation of m

void p( int list[], int arraySize) // definition of Function p

{

list[0] = 100; // making value of first element of list as 100

}

int main()

{

int x = 1; // initilizing x with 1

int y[10]; // y is a array of 10 elements

y[0] = 1; // first element of y array is 1

m(x, y); // call m function

// printing the desired result

cout << "x is " << x << endl;

cout << "y[0] is " << y[0] << endl;

return 0;

}

void m(int number, int numbers[]) // Function definition of m

{

number = 1001; // value of number is 1001 locally

numbers[0] = 5555; // making value of first element of numbers array 5555

}

Part C :-

In program we initilize x with value 1 and create an array y of 10 elements.

we initilize the y[0] with 1\

then we call function m. In function m ,first argument is value of x and second argument is the pointer to the first element of array y.

so value of x is changed locally in function m and change is not reflected in main function.

but value of y[0] is changed to 5555 because of pass by refrence.

So we are getting the following result :-

x is 1

y[0] is 5555

4 0
3 years ago
When implementing a safety and health program, management leadership does not need employee participation a True b) False Effect
sladkih [1.3K]

Answer: I have answered the questions in rephrased sentences as below;

When implementing a safety and health program, management leadership need employee participation. Effective management of worker safety and health programs has improved employee productivity and morale in the workplace.

Nearly a third of all serious occupational injuries and illnesses stem from overexertion of repetitive motion.

Training is a way for employers to provide tools to enable employees to protect themselves and others from injuries.

Under OSHA, employees are protected from discrimination when reporting a work-related injury, illness, or fatality.

Explanation: All personnel including management & employees must be directly involved when workplace HSE policies are being made & reviewed. This is because everyone in the work environment is impacted one way or the other when incidents occur.

Training & Reporting are key responsibilities of managers, employers & supervisors, so it is mandatory to be done without discrimination so as to foster employees happiness which ultimately lead to zero incidents & increased productivity & profit.

3 0
3 years ago
tech A says that a Hall-effect sensor can be used in an electronic ignition system. Tech B says that an optical-type sensor can
Alex

Answer:

<em>Both Tech A and Tech B are correct.</em>

<em>Explanation:</em>

<em>The Hall effect sen sensor are used to control displacements and rotations of various body components  of the vehicles, engine vibrations , and the ignition   system</em>

<em>The  optical-type sensor converts rays of light  into electronic signals. It measures the quantity physically of which the translates to a form that is understandable or readable  by an instrument. An optical sensor is larger part of a  system that integrates light sources, a device for measuring  and the optical sensor, which therefore is usually  connected to an electrical trigger.</em>

6 0
3 years ago
Other questions:
  • Consider 4.8 pounds per minute of water vapor at 100 lbf/in2, 500 oF, and a velocity of 100 ft/s entering a nozzle operating at
    6·1 answer
  • A turbine operates at steady state, and experiences a heat loss. 1.1 kg/s of water flows through the system. The inlet is mainta
    6·1 answer
  • The increasing interconnections of peoples and countries around the world is known as ________.
    14·2 answers
  • 1. Saturated steam at 4 bars absolute pressure with a mean velocity of 3 m/s flows through a horizontal SS304 stainless-steel pi
    6·1 answer
  • WHAT IS THIS PLSSSSSS HELP
    13·1 answer
  • HELP PLS<br> Is a book a solid, frame, shell or combination and WHY
    6·2 answers
  • Select the correct answer.
    11·2 answers
  • A differential amplifier is to have a voltage gain of 100. What will be the feedback resistance required if the input resistance
    7·1 answer
  • Why Elastic Modulus is important and on what it depends?
    12·1 answer
  • What is the role of engineers in nation building <br><br>​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!