Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Random;
- public class ArrayCombo {
- static Random randomGenerator = new Random();
- public static int masterArray[];
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int thread1[] = new int[16];
- int thread2[] = new int[16];
- int thread3[] = new int[16];
- int thread4[] = new int[16];
- int finalThread[] = new int[32];
- for (int i = 0; i < 16; i++) {
- thread1[i] = randomGenerator.nextInt(100);
- thread2[i] = randomGenerator.nextInt(100);
- thread3[i] = randomGenerator.nextInt(100);
- thread4[i] = randomGenerator.nextInt(100);
- }
- Arrays.sort(thread1);
- Arrays.sort(thread2);
- System.out.print("The first thread contains : ");
- for (int i = 0; i < 16; i++) {
- System.out.print(" " + thread1[i]);
- }
- System.out.println();
- System.out.print("The second thread contains :");
- for (int i = 0; i < 16; i++) {
- System.out.print(" " + thread2[i]);
- }
- combineArrays(thread1, thread2);
- System.out.println();
- System.out.print("The Master thread contains :");
- for (int i = 0; i < 32; i++) {
- System.out.print(" " + masterArray[i]);
- }
- }
- private static void combineArrays(int a[], int b[]) {
- masterArray = new int[32];
- int i = 0;
- int j = 0;
- System.out.println();
- for (int x = 0; x < 32; x++) {
- if (a[i] < b[j]) {
- masterArray[x] = a[i];
- i++;
- }
- else{
- masterArray[x] = b[j];
- j++;
- }
- if (i == a.length) {
- for (int s = j; s < b.length; s++) {
- x++;
- masterArray[x] = b[s];
- }
- x = 32;
- }
- if (j == b.length) {
- for (int s = i; s < a.length; s++) {
- x++;
- masterArray[x] = a[s];
- }
- x = 32;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement