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
Nonamiya [84]
3 years ago
12

Write the following method that merges two sorted arrays into a new sorted array public static int [] merge(int [] array1, int [

] array2) { // add your code here } public static void main(String [] args) { int [] array1 = {1, 5, 16, 61, 111}; int [] array 2 = {2, 4, 5, 6} int [] mergedArray = merge(array1, array2); System.out.println(Arrays.toString(mergedArray)); } java doc
Computers and Technology
1 answer:
uysha [10]3 years ago
7 0

Answer:

See explaination

Explanation:

import java.util.Arrays;

public class MergeArrays {

public static int[] merge(int[] array1, int[] array2) {

int[] result = new int[array1.length + array2.length];

int i = 0, j = 0, k = 0;

while (i < array1.length && j < array2.length) {

if (array1[i] < array2[j]) result[k++] = array1[i++];

else result[k++] = array2[j++];

}

while (i < array1.length) result[k++] = array1[i++];

while (j < array2.length) result[k++] = array2[j++];

return result;

}

public static void main(String[] args) {

int[] array1 = {1, 5, 16, 61, 111};

int[] array2 = {2, 4, 5, 6};

int[] mergedArray = merge(array1, array2);

System.out.println(Arrays.toString(mergedArray));

}

}

You might be interested in
What is the difference, if any, between secure HTTP and firewalls?
Jobisdone [24]

Answer:

SSL would simply encrypt whatever request is sent to the server. In order to prevent the execution of such malicious scripts/payloads at the Web application (in other words the Web server), a Web Application Firewall is implemented in place. ... Whereas, HTTPS where SSL comes into picture would have methods such as POST.

in other words its A

5 0
3 years ago
In a non-price rationing system, consumers receive goods and services first-come, first served. Give me an example of a time whe
Anna35 [415]

When someone may be giving away something for free.

7 0
2 years ago
In Java an abstract class cannot be sub-classed<br><br> ?? True<br><br> ?? False
mojhsa [17]

Answer:

False

Explanation:

An abstract class is a class declared abstract — it may or may not include abstract techniques. It is not possible to instantiate abstract classes, but they can be sub-classed.

<u></u>

<u>Abstract method declaration</u>

             

         abstract void moveTo(double X, double Y);

Usually the subclass offers solutions for all of the abstract techniques in its parent class when an abstract class is sub-classed. If not, however, the subclass must be declared abstract as well.

<u>Example</u>

public abstract class GraphicObject {

  // declaring fields

  // declaring non-abstract methods

  abstract void draw();

}

8 0
3 years ago
2.Use loops to create a 4X6 matrix in which the value of each element is two times its row number minus three times its column n
DiKsa [7]

Answer:

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

{

      for(j=0;j<6;j++)

      {

               A[ i ][ j ] = 2* i - 3*j;

      }

}

Explanation:

In this loop for each i = 0,1,2,3 we fill the the corresponding column values. and then move to next i value i.e. row.

3 0
3 years ago
Which of the following is a reliable source of information: a book recommended from my professor, britannica, a blog, or wikiped
ratelena [41]
A book recommended from your professor is a reliable source of information.
8 0
3 years ago
Other questions:
  • Server farms such as Google and Yahoo! provide enough compute capacity for the highest request rate of the day. Imagine that mos
    12·1 answer
  • Data mining must usestatistics to analyze data.<br> True<br> False
    12·1 answer
  • What is NOT a good habit when presenting to an audience?
    5·2 answers
  • Taking a suitable example in c language explain the of call by value and call by reference concepts.
    7·1 answer
  • Choose the HTML5 element below that is used to configure an area on a web page that can stand on its own and could potentially b
    5·1 answer
  • Which of the following is a common financial aid scam that students sometimes find on the Internet? Grant and scholarship databa
    8·2 answers
  • A workstation with a static IP (Internet Protocol) address can print and authenticate to a server, but cannot browse to www.comp
    14·1 answer
  • highlight the possible risks and problems that should be address during the implementation of information system process
    5·1 answer
  • What type of bus does PCI use?
    10·1 answer
  • Discuss the ways you can perform to prevent your computer/device and its data/contents from being stolen. Define two-facto authe
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!