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
Point to ______ of a cell to fill the cell to the right or down.
UNO [17]

Answer:

It's "The bottom left corner"

Explanation:

8 0
2 years ago
Read 2 more answers
Create a method called randomValues that uses a while loop to generate a random number between 1-25 until the value 10 is genera
ahrayia [7]

Answer:

The method in Java is as follows:

public static void randomValues(){

    Random r = new Random();

    int sentinel = 10;

    int randNum = r.nextInt(24) + 1;

    while(randNum!=sentinel){

        System.out.print(randNum+" ");

        randNum = r.nextInt(24) + 1;

    }

    System.out.print(sentinel);

}

Explanation:

This defines the method

public static void randomValues(){

This creates a random object, r

    Random r = new Random();

This sets the sentinel value to 0

    int sentinel = 10;

This generates a random number

    int randNum = r.nextInt(24) + 1;

This loop is repeated until the the random number is 10

    while(randNum!=sentinel){

Print the generated number

        System.out.print(randNum+" ");

Generated another random number

        randNum = r.nextInt(24) + 1;     }

Print the sentinel (i.e. 10)

    System.out.print(sentinel);

}

3 0
3 years ago
¿que significa “TTAQMMQMPDATLSPLNDTMGCCLFEQMMPQTEIUMDR” ?
OlgaM077 [116]

Answer: what

Explanation:

5 0
3 years ago
Read 2 more answers
16. Budget Analysis Write a program that asks the user to enter the amount that he or she has budgeted for a month. A loop shoul
strojnjashka [21]

Answer:

import java.util.Scanner;

public class num8 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter month's budget");

       double monthBudget = in.nextDouble();

       double totalExpenses = 0.0;

       double n;

       do{

           System.out.println("Enter expenses Enter zero to stop");

           n = in.nextDouble();

           totalExpenses += n;

       }while(n>0);

       System.out.println("Total expenses is "+totalExpenses);

System.out.println("The amount over your budget is "+ Math.abs(monthBudget-totalExpenses));

   }

}

Explanation:

  • Using Java programming language
  • Prompt user for month's budget
  • Use Scanner class to receive and store the amount entered in a variable
  • Use a do while loop to continuously request user to enter amount of expenses
  • Use a variable totalExpenses to add up all the expenses inside the do while loop
  • Terminate the loop when user enters 0 as amount.
  • Subtract totalExpenses from monthBudget and display the difference as the amount over the budget

6 0
3 years ago
Consider the following code:
weqwewe [10]

Answer:

252

Explanation:

I tested the code and it outputted 252

hope i helped :D

4 0
3 years ago
Other questions:
  • What does the picture indicate on the famous book “Dawn of the century”?​
    10·1 answer
  • Despite its vivid design, the website for Lolly's Bookstore did not seem to attract customers who lingered. In fact, most websit
    13·1 answer
  • Which statement best represents the denotation for the word “woman”? A woman is an adult human female. Both man and woman are re
    11·2 answers
  • "the magical number seven, plus or minus two" refers to the storage capacity of ________ memory.
    5·2 answers
  • "Because Standard Error and Standard Ouput represent the results of a command and Standard Input represents the input required f
    6·1 answer
  • Which of the following technologies is the best choice to convey urgent and highly sensitive information?a. Telephone b. Fax Let
    12·1 answer
  • Your marketing director at ABC Marketing Agency would like to set up an email campaign that will use personalization to referenc
    5·1 answer
  • CALLING ALL DEKUS UWU
    15·2 answers
  • Your program will be used by many departments at the university. Your comments will be important to their IT people. What would
    13·1 answer
  • Which shortcut keys can be used to duplicate a slide?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!