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
SSSSS [86.1K]
3 years ago
13

Problem 2 Write a method that (a) returns an int[] , (b) takes in two sorted arrays (in descending order) and (c) returns an int

[] with sorted values (in descending order) from the two sorted arrays. The method will also print out the number of compares done. int[] a = new int[]{18, 16, 15, 6, 2}; int[] b = new int[]{13, 12, 11, 7, 1}; public int[] sortArraysDes(int[] a, int[] b){ //your code here } The int[] returned should have all the integers from int[]a and int[]b in descending order.
Computers and Technology
1 answer:
Galina-37 [17]3 years ago
4 0

Answer:

Following are the Program in the Java Programming Language.

//define class

public class Main

{

//define function to merge and sort array

public static int[] sort_Array(int[] a, int[] b)

{

//set integer variable and initialize values

int x = 0, y = 0, k = 0, num = 0;

int n = a.length;

int n1 = b.length;

//set integer type array

int[] ar = new int[n+n1];

//set while loop

while (x<n && y <n1)

{

num++;

num++;

//set if conditional statement

if (a[x] > b[y])

ar[k++] = a[x++];

else

ar[k++] = b[y++];

num++;

}

//set the while loop

while (x < n)

{

num++;

ar[k++] = a[x++];

}

//set the while loop

while (y < n1)

{

num++;

ar[k++] = b[y++];

}

//print the total compares done

System.out.println("Number of compares done: " + n);

//return array

return ar;

}

//define main method

public static void main(String[] args)

{

//declaration and the initialization of array

int[] a = new int[]{18,16, 15, 6, 2};

int[] b = new int[]{13, 12, 11, 7, 1};

int[] ar;

//call function

ar = sort_Array(a, b);

//print message

System.out.println("\nThe resultant array is: \n");

//set for loop to print array

for(int x=0; x<ar.length; x++)

{

System.out.print(ar[x] + " ");

}

}

}

<u>Output</u>:

Number of compares done: 5

The resultant array is:

18 16 15 13 12 11 7 6 2 1

Explanation:

Here, we define a class "Main" inside the class, define a function "sort_Array()"and pass two integer type array argument "a" and "b".

  • Set four integer type variables "x", "y", "k", and "num" and initialize them to 0.
  • Set two integer type array "n", "n1" and initialize them the length of the array then, set integer type array variable "ar".
  • Set the while loop then, set if conditional statement then, agin set while loop to sort array in descending order.
  • Then, print the number of compares and return the value of the variable "ar".

Finally, define the main method inside it, we set two integer type array variable and initialize elements in them then, set the for loop to print the sorted elements of the array.

You might be interested in
When the user types into a Textbox control, the text is stored in the control's __________ property.
joja [24]

The property that stores the text a user types into a Textbox is called the: control's text property.

<h3>The Textbox Control</h3>

The Textbox Control is employed in display a text or accept the text as an input from a user. Also, single line of text can be accepted as input at runtime from a VB.NET Windows.

The text that displays on the Textbox can also be set. The control's text property therefore stores the text a user types into Textbox.

In conclusion, the property that stores the text a user types into a Textbox is called the: control's text property.

Learn more about Textbox Control on:

brainly.com/question/5677552

3 0
2 years ago
A struggle between opposing forces or characters is
tamaranim1 [39]

Answer:

Conflicts

Explanation:

The struggle between two opposing forces or characters in a story. Conflicts can exist between two people, between a person and nature or a machine or between a person a whole society. a conflict can be internal, involving opposing forces within a person's mind.

4 0
3 years ago
Please answer quick :(​
Karo-lina-s [1.5K]

Answer:

1<2 or 15<6 is true

2<4 and 7< 3 is false

not(7>2) is false

6 0
1 year ago
Read 2 more answers
If every company is now a technology company, then what does this mean for every student attending a business college
timofeeve [1]

Answer:

Explanation:

There are all sorts of possibilities for, say, inserting new technologies into existing processes. But most of these improvements are incremental. They are worth doing; in fact, they may be necessary for survival. No self-respecting airline, for instance, could do without an application that lets you download your boarding pass to your mobile telephone. It saves paper, can't get lost and customers want it.

But while it's essential to offer applications like the electronic boarding pass, those will not distinguish a company. Electronic boarding passes have already been replicated by nearly every airline. In fact, we've already forgotten who was first.

5 0
3 years ago
I need help plzzzzzzzz
Blababa [14]

Answer:

The output is second half of the month, refers to both

4 0
3 years ago
Read 2 more answers
Other questions:
  • Soo...My Old 3DS XL haven't been touched in around a year...So i tried to charge it but no LED lights opened..Even the power but
    14·1 answer
  • the equation t= 0.25d^1/2 can be used to find the number of seconds, t, that it takes an object to fall a distance of d feet how
    8·1 answer
  • Which of the following Office Online apps is most effective for creating multi-media presentations
    15·1 answer
  • Print a countdown from n to 1 The function below takes one parameter: an integer (begin). Complete the function so that it print
    8·1 answer
  • 14. Convert 11110111 from binary to denary<br> (1 Point)
    12·2 answers
  • Programming assignment (100 pts): In the C++ programming language write a program capable of playing Tic-Tac-Toe against the use
    14·1 answer
  • . If you have written the following source code:
    9·1 answer
  • Leah wants to add an image to her updated presentation, so she wants to access the Help interface. What should
    11·2 answers
  • Which character is cannot be used in a file name _ (underscore)/ (backslash)- (hyphen) % ( percent)
    12·1 answer
  • Lab 8-1: Working with Boot Loader and Runlevels what is the root password
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!