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
Kryger [21]
3 years ago
7

Write a program called interleave that accepts two ArrayLists of integers list1 and list2 as parameters and inserts the elements

of list2 into list1 at alternating indexes. If the lists are of unequal length, the remaining elements of the longer list are left at the end of list1.
Computers and Technology
1 answer:
nata0808 [166]3 years ago
7 0

Answer:

Explanation code is given below along with step by step comments!

Explanation:

// first we create a function which accepts two ArrayList of integers named list1 and list2

public static void interleave(ArrayList<Integer> list1, ArrayList<Integer> list2)

{

// we compare the size of list1 and list2 to get the minimum of two and store it in variable n

   int n = Math.min(list1.size(), list2.size());

   int i;

// here we are getting the elements from list2 n times then we add those elements in the list1 alternating (2*i+1)

   for (i = 0; i < n; i++)

     {

       int x = list2.get(i);

       list1.add(2 * i + 1, x);

      }

// if the size of list1 and list2 is same then program stops here else we need to append extra elements at the end of list1

// then we check if the size of list2 is greater than list1 then simply add the remaining elements into list1

   if (i < list2.size())

{

       for (int j = i; j < list2.size(); j++)

           {

                list1.add(list2.get(j));

            }  

     }  

}

Sample Output:

list1=[1, 2, 3]

list2=[5, 6, 7, 8, 9]

list1=[1, 5, 2, 6, 3, 7, 8, 9]

You might be interested in
The _____ icon allows the user to improve the brightness, contrast, or sharpness of the picture.
bija089 [108]

Answer:

The Corrections icon

Explanation:

In Office 2010, 2013, 2016, you can adjust the brightness, contrast, and the sharpness of a picture. This can be achieved by using the corrections tool. Assuming you already have the picture, click on it and on the Format tab, under the Pictures tools, in the Adjust group, click Corrections. Under the Sharpen/Soften or the Brightness/Contrast, you can click the thumbnails that you want to make adjustments.

4 0
2 years ago
I have tried many times to find a gaming setup for $4k. I have tried many websites but they are not working for my liking. Any o
Vikentia [17]
I would try going to pcpartpicker.com and build your pc from there, and after you’ve done that take your remaining budget to find whatever else you need for your setup
8 0
2 years ago
CHALLENGE ACTIVITY |
fredd [130]

Answer:

maxSum = FindMax(numA, numB) + FindMax(numY, numZ);  

The maxSum is a double type variable which is assigned the maximum of the two variables numA numB PLUS the maximum of the two variables numY numZ using FindMax function. The FindMax() method is called twice in this statement one time to find the maximum of numA and numB and one time to find the maximum of numY numZ. When the FindMax() method is called by passing numA and numB as parameters to this method, then method finds if the value of numA is greater than that of numB or vice versa. When the FindMax() method is called by passing numY and numZ as parameters to this method, then method finds if the value of numY is greater than that of numZ or vice versa. The PLUS sign between the two method calls means that the resultant values returned by the FindMax() for both the calls are added and the result of addition is assigned to maxSum.

Explanation:

This is where the statement will fit in the program.

#include <iostream>

using namespace std;

double FindMax(double num1, double num2) {

  double maxVal = 0.0;    

  if (num1 > num2) { // if num1 is greater than num2,

     maxVal = num1;  // then num1 is the maxVal.    }

  else {          

     maxVal = num2;  // num2 is the maxVal.   }

  return maxVal; }  

int main() {

  double numA;

  double numB;

  double numY;

  double numZ;

  double maxSum = 0.0;  

maxSum = FindMax(numA, numB) + FindMax(numY, numZ);  

  cout << "maxSum is: " << maxSum << endl;   }

Lets take an example to explain this. Lets assign values to the variables.

numA = 6.0

numB = 3.0

numY = 4.0

numZ = 9.0

maxSum =0.0

maxSum = FindMax(numA, numB) + FindMax(numY, numZ);  

FindMax(numA,numB) method call checks if numA>numB or numB>numA and returns the maximum of the two. Here numA>numB because 6.0 is greater than 3.0. So the method returns numA i.e. 6.0

FindMax(numY, numZ) method call checks if numY>numZ or numZ>numY and returns the maximum of the two. Here numZ>numY because 9.0 is greater than 4.0. So the method returns numZ i.e. 9.0

FindMax(numA, numB) + FindMax(numY, numZ) this adds the two values returned by the method FindMax for each call.

FindMax returned maxVal from numA and numB values which is numA i.e. 6.0.

FindMax returned maxVal from numY and numZ values which is numZ i.e. 9.0.

Adding these two values 9.0 + 6.0 = 15

So the complete statement  FindMax(numA, numB) + FindMax(numY, numZ) gives 15.0  as a result.

This result is assigned to maxSum. Hence

maxSum = 15

To see the output on the screen you can use the print statement as:

cout<<maxSum;

This will display 15

6 0
3 years ago
How do i make a PDF and what is a PDF<br><br> sorry i am dumb
Soloha48 [4]

Answer:

............................................

Explanation:

5 0
2 years ago
Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and events (like the 10 or 90
Norma-Jean [14]

Answer:

The C code for the problem is given below

Explanation:

#include <stdio.h>

int main() {

   int highwayNumber;

   int primaryNumber;

   scanf("%d", &highwayNumber);

   if (highwayNumber >= 1 && highwayNumber <= 999) {

       if (highwayNumber <= 99) {

           if (highwayNumber % 2 == 0) {

               printf("I-%d is primary, going east/west.\n", highwayNumber);

           } else {

               printf("I-%d is primary, going north/south.\n", highwayNumber);

           }

       } else {

           primaryNumber = highwayNumber;

           highwayNumber %= 100;

           if (highwayNumber % 2 == 0) {

               printf("I-%d is auxiliary, serving the I-%d, going east/west.\n", primaryNumber, highwayNumber);

           } else {

               printf("I-%d is auxiliary, serving the I-%d, going north/south.\n", primaryNumber, highwayNumber);

           }

       }

   } else {

       printf("%d is not a valid interstate highway number.\n", highwayNumber);

   }

   return 0;

}

4 0
2 years ago
Read 2 more answers
Other questions:
  • As yall know its spoopy season. This means spoopy music! I am having a live stream on the Spoon app under the username teendrago
    11·1 answer
  • Original Problem statement from the Text: A retail company must file a monthly sales tax report listing the sales for the month
    7·1 answer
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    8·1 answer
  • Anybody know this question??
    8·1 answer
  • Hypercompetition implies that any architecture must be designed with maximum flexibility and _____ to ensure it can handle the i
    6·1 answer
  • Pls help have absolutely no clue how to delete this
    12·2 answers
  • Users who are connecting to an NLB cluster have been complaining that after using the site for a few minutes they are prompted t
    15·1 answer
  • Which phrase is the best definition of sparklines in Excel 2016?
    8·2 answers
  • How do people decide their ethical behavior
    13·2 answers
  • ____________ are designed to delete temporary files (such as deleted files still in the Recycle Bin, temporary Internet files, t
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!