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
Mandarinka [93]
3 years ago
6

Method: public ArrayList diff(ArrayList list1, ArrayList list2) {} diff() method accepts two ArrayLists of Integer and returns t

he union of elements in two lists. (15 pts) Test case: list1: 1, 2, 3, 4, 5 list2: 3, 4, 5, 6, 7 This method should return an array list with elements 1, 2, 3, 4, 5, 6, 7
Computers and Technology
1 answer:
babymother [125]3 years ago
5 0

Answer:

(Assuming Java)

public ArrayList diff(ArrayList list1, ArrayList list2) {

   ArrayList<Integer> union = new ArrayList<>();

   for (int element : list1) {

       union.add(element);

   }

   for (int element : list2){

       if (!union.contains(element)) {

           union.add(element);

       }

   }

   return union;

}

Explanation:

Create an ArrayList that has the union of list1 and list2.

First for loop copies all elements into the union array list.

Second for loop adds all elements that are not yet in the union arraylist to the union arraylist.

(Keep in mind that I assume that you mean a mathematical union, so no duplicates. If this is not what you mean, remove the if statement in the second for loop)

You might be interested in
Is the process of modifying something to make it fit certain criteria.
alexandr402 [8]

Answer:

Design Process

8 0
3 years ago
The hypothalamus controls the anterior pituitary by means of: a. releasing hormones b. second messengers c. third messengers d.
scoundrel [369]

Answer:

a. releasing hormones

Explanation:

The hypothalamus controls the anterior pituitary by means of corticotropin-releasing hormone (CRH). The hormone CRH is encoded by the CRH gene on eighth human chromosome. The anterior pituitary in turn regulates other endocrine glands by means of Adrenocorticotrophic Hormone (ACTH). These actions form part of the Hypothalamic–pituitary–adrenal(HPA) axis which is one of the important neuroendocrine systems in humans.

7 0
3 years ago
Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha. Wri
Alina [70]

Answer:

In Java:

public static  int[] inputArray(){

   Scanner input = new Scanner(System.in);

   int[] alpha = new int[20];

   for(int i = 0;i<20;i++){

       alpha[i] = input.nextInt();

   }

   return alpha;}

public static  int[] doubleArray(int [] alpha){

   int[] beta = new int[20];

   for(int i = 0;i<20;i++){

       beta[i] = 2 * alpha[i];

   }

   return beta;

}

public static int[] copyAlphaBeta(int [] alpha, int [] beta){

   int [] AlphaBeta = new  int[10];

   for(int i = 0;i<5;i++){

       AlphaBeta[i] = alpha[i];

   }

   int count = 5;

   for(int i = 15;i<20;i++){

       AlphaBeta[count] = beta[i];

       count++;

   }

   return AlphaBeta;

}

public static void printArray(int [] alpha){

   for(int i = 0;i<20;i++){

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

       if((i+1)%15 == 0){

           System.out.println(" ");

       }

   }

}

Explanation:

The inputArray is defined here

public static  int[] inputArray(){

   Scanner input = new Scanner(System.in);

This declares alpha array of 20 elements

   int[] alpha = new int[20];

The following iteration gets input from the user into the array

<em>    for(int i = 0;i<20;i++){</em>

<em>        alpha[i] = input.nextInt();</em>

<em>    }</em>

This returns the alpha array

   return alpha;}

The doubleArray is defined here. It takes the alpha array as its input parameter

public static  int[] doubleArray(int [] alpha){

This declares beta of 20 integers

   int[] beta = new int[20];

This populates beta by 2 * alpha[i]

<em>    for(int i = 0;i<20;i++){</em>

<em>        beta[i] = 2 * alpha[i];</em>

<em>    }</em>

This returns the alpha array

   return beta;}

The copyAlphaBeta array is defines here

public static int[] copyAlphaBeta(int [] alpha, int [] beta){

This declares AlphaBeta as 10 elements

   int [] AlphaBeta = new  int[10];

This populates the first 5 elements of AlphaBeta with the first 5 of alpha

<em>    for(int i = 0;i<5;i++){</em>

<em>        AlphaBeta[i] = alpha[i];</em>

<em>    }</em>

   int count = 5;

This populates the last 5 elements of AlphaBeta with the last 5 of beta

<em>    for(int i = 15;i<20;i++){</em>

<em>        AlphaBeta[count] = beta[i];</em>

<em>        count++;</em>

<em>    }</em>

This returns the AlphaBeta array

   return AlphaBeta;

}

The printArray is defined here. It takes the alpha array as its input parameter

public static void printArray(int [] alpha){

This iterates through alpha array

   for(int i = 0;i<20;i++){

This prints each element of the array

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

A new line is started after the 15th element

<em>        if((i+1)%15 == 0){</em>

<em>            System.out.println(" ");</em>

<em>        }</em>

   }

}

See attachment for complete program which includes the main

Download txt
4 0
3 years ago
How many times will the loop body execute:
Xelga [282]
I’d also say B, which is 2
6 0
3 years ago
Using the FAFSA form , you can for apply for what
AlladinOne [14]

apply for financial aid for college or grad school.

7 0
3 years ago
Read 2 more answers
Other questions:
  • If a hypothesis is strongly supported by the scientific community based on compelling experiment results, it becomes a————
    10·2 answers
  • Find a 95% confidence interval for the mean failure pressure for this type of roof panel.The article "Wind-Uplift Capacity of Re
    7·1 answer
  • To answer the research question "How am I going to find the information I need on the tople?" the best thing Georgia should
    15·1 answer
  • Explain three specific &amp; major security threats to internet users. In each case, address whether or not the vulnerabilities
    15·1 answer
  • What happens if you create multiple accounts just to get points faster?
    6·1 answer
  • What are the 3 rules of music<br><br> ps: there is no music subject so i had to put something else
    15·2 answers
  • How many questions do you have to answer before you can use direct messages on Brainly?
    13·2 answers
  • Look at (c), is it accurate? ​
    9·2 answers
  • Identify the correct answer in each item. Write your answer on the blank provided before
    13·1 answer
  • Is e commerce a challenge or opportunity to the freight forwarder
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!