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
By default, windows does not display ____________________ in windows explorer.
OlgaM077 [116]
The answer is file extensions.
8 0
3 years ago
When using an hdmi to dvi adapter, what two dvi port types will the adapter work with?
Inga [223]
When using an HDMI to DVI adapter, the adapter will work with two DVI ports which are <span>DVI-D and DVI-I ports

</span>DVI<span> is a digital signal that has the same format as the video portion of </span>HDMI<span>. However, </span>DVI<span> doesn't carry the audio signal whereas the </span>HDMI does<span>.
This means that if you are only using the video signal you can use a simple </span>DVI to HDMI<span> plug-</span>adapter<span> that changes the physical connections.</span> 
5 0
4 years ago
Distance Traveled The distance a vehicle travels can be calculated as follows: For example, if a train travels 40 miles per hour
solmaris [256]

Answer:

speed = int(input("Enter the speed: "))

hour = int(input("Enter the hour: "))

for i in range(1, hour + 1):

   distance = speed * i

   print("The distance traveled after " + str(i) + " hour(s): " + str(distance))

Explanation:

Ask the user for the speed and hour as input

Initialize a for loop that iterates from 1 to the given hours

Calculate the distance after each hour, multiply speed by hour

Print the distance after each hour

8 0
3 years ago
To adjust the margins on a page, users will navigate to the _____ tab.
sashaice [31]
It should be layout or header
6 0
3 years ago
Read 2 more answers
Which of the following Internet protocols is MOST important in reassembling packets and requesting missing packets to form compl
Ratling [72]

Answer:

Transmission Control Protocol (TCP)

Explanation:

On the network architecture for connecting to the internet, the output intended to be sent over the internet by an application are split into packets and pushed for delivery by one of two protocols; TCP or User Datagram Protocol

These protocols are also responsible for taking the messages contained in the packets for onward delivery to the relevant application via ports

However, TCP gathers and arranges the received packets in the correct order as the originally sent message as well as requesting the retransmission of packets that are damaged or lost from the sending server so as to include their payloads in order to complete the original message.

8 0
3 years ago
Other questions:
  • How much time does one person spend on social media in one year
    12·2 answers
  • PLEASE HURRY
    6·1 answer
  • Computer science
    6·1 answer
  • Given variables first and last, each of which is associated with a str, representing a first and a last name, respectively. Writ
    13·1 answer
  • Create a class Str that subclasses str. Add a method to the subclass that checks if the string does not start with a given strin
    15·1 answer
  • The growing network of physical objects that will have sensors connected to the Internet is referred to as the ________.
    13·1 answer
  • LEAF library in py can be expressed in what form?
    6·1 answer
  • What is the Purpose and function of the Global Positioning System (GPS)?
    7·1 answer
  • ____allow(s) visually impaired users to access magnified content on the screen in relation to other parts of the screen.
    5·1 answer
  • Given a string, an integer position, and an integer length, all on separate lines, output the substring from that position of th
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!