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]
4 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]4 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
As the internet continues to expand and become vital to everyday life, it may become more regulated with rules just like our eve
denis23 [38]
I can't see all of option D, but it is potentially correct. Please tell me what option D is and I will tell you if it is option "B" or option "D."
5 0
3 years ago
Read 2 more answers
Which of the following gestures would you use if you want to activate a link on your new tablet?
Gre4nikov [31]

Answer:

press and hold

Explanation:

When you press and hold, some open a menu where you can add a link

8 0
3 years ago
Complete the steps to evaluate the following
kirill115 [55]

Answer:

log base 3a= -0.631.log a/3 base 3

Now, -log m= log 1/m

hence,

log base 3a= 0.631.log 3/a base 3

log base 3a/log 3/a base 3 =0.631

log base 3 ( a.3/a) =.631 since, log m/logn =log n(m)

log base 3 3=0.631

Hence, answer is log base 3 3=0.631

Explanation:

Please check the answer section.

3 0
3 years ago
Read 2 more answers
Annalisa needs to total the amounts she spent at Starbucks in the last month. She has entered all the amounts from her receipts
Zarrin [17]

Answer:

The answer is c

Explanation:

6 0
3 years ago
A user is trying to delete a file located on an NTFS volume on his Windows 8 computer but is unable to do so. Why is this?
Molodets [167]

There can be several reasons why the user is not able to delete a file on the NTFS Volume or disk partition of the computer. Possible scenarios are as follows.

1. The user does not have sufficient permission to perform the task as the file itself may not be owned with the user. The best way is to make sure the user is an administrator.

2. The file is corrupted which prevents to properly access, running a chkdsk will help to validate with this.

3. Another common scenario is that the file is actually currently in use.

4 0
3 years ago
Other questions:
  • Why aren't the answers visible anymore? Thanks!
    8·2 answers
  • Put the following five steps in the order in which you would perform them to use the Paste Special function: ____. 1. Select and
    5·1 answer
  • Acomputer with a domain name is called a
    8·1 answer
  • Consider the following methods:
    10·1 answer
  • What are two most common types of microcomputers? a. IBM-style PCs and Macs c. Clients and Servers b. Mainframes and Minicompute
    14·1 answer
  • Damian uses a modem to connect to a dial-up network. Which statements are true of a modem?
    11·2 answers
  • Why dose this keep popping up i dont understand plz resond first person gets branilest
    13·1 answer
  • The objects that you place on master pages are called _____.
    6·1 answer
  • Which of the following is the last step in creating a budget?
    13·1 answer
  • What extra dimension do 3D objects have that 2D objects do not have?<br><br> help
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!