NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.util.Random;
import java.util.Arrays;

public class ArrayMeld {
public static int[] meld(int[] a, int[] b){
// Declaring Varialbes
int i = 0,j = 0,k= 0,a_size = a.length , b_size = b.length; //a.length returns the length of the array
int[] sorted_arr = new int[a.length + b.length]; // Declaring a new array with size of a.lenght + b.length
while(i<a_size && j<b_size){ // Iterating until one of the array gets completed.
if(a[i] < b[j]){ // comparing to get smaller element of two arrays.
sorted_arr[k++] = a[i++]; // assigning smaller element to sorted_arr
}
else{
sorted_arr[k++] = b[j++];
}
}
if (i<a_size){ //If still have elements in 'a'
System.arraycopy(a,i,sorted_arr,k,a_size-i); // elements of 'a' from index 'i' up to end
} //are copied into sorted_arr from index 'k'
if (j<b_size){ //If still have elements in 'b'
System.arraycopy(b,j,sorted_arr,k,b_size-j); // Same as above.
}
return sorted_arr; // returning sorted array.
}
// Given functions
public static int[] nextArray(int maxLength){
Random r = new Random();
int length = r.nextInt(maxLength + 1);
return new int[length];
}
public static void populateArray(int[] array, int maxValue){
Random r = new Random();
for (int i = 0;i < array.length; i++){
array[i] = r.nextInt(maxValue +1);
}
}
public static void main(String[] args) {
int[] arr1 = nextArray(7);
int[] arr2 = nextArray(7);

populateArray(arr1,9);
populateArray(arr2,9);

Arrays.sort(arr1);
Arrays.sort(arr2);

System.out.print("arr1 is ");
System.out.println(Arrays.toString(arr1));
System.out.print("arr2 is ");
System.out.println(Arrays.toString(arr2));

int[] arr3 = meld(arr1,arr2);

System.out.print("arr3 is ");
System.out.println(Arrays.toString(arr3));
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.