Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class assignmentsix {
- @SuppressWarnings("null")
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- int count1 = 0;
- int count2 = 0;
- int temp = 0;
- int [] ray1 = new int [10000];
- int [] sting1 = new int [10000];
- System.out.println("Enter the values for the first array, up to 10000 values, enter a negative number to quit");
- for (int i = 0; i < ray1.length; i++)
- {
- ray1[i] = scan.nextInt();
- count1++;
- if (ray1[i] < 0)
- {
- break;
- }
- }
- System.out.println("Enter the values for the second array, up to 10000 values, enter a negative number to quit");
- for (int k = 0; k < sting1.length; k++)
- {
- sting1[k] = scan.nextInt();
- count2++;
- if (sting1[k] < 0)
- {
- break;
- }
- }
- //new array w/o 0's for ray
- int [] ray2 = new int [count1 - 1];
- for (int u = 0; u < count1 - 1; u++)
- {
- ray2[u] = ray1[u];
- }
- //new array w/o 0's for sting
- int [] sting2 = new int [count2 - 1];
- for (int o = 0; o < count2 - 1; o++)
- {
- sting2[o] = sting1[o];
- }
- int [] combined = new int [(count1 - 1) + (count2)];
- for (int z = 0; z < count1 - 1; z++)
- {
- combined[z] = ray2[z];
- }
- for (int x = count1 ; x < count2 + count1 - 2; x++)
- {
- combined[x] = sting2[x-count1];
- }
- System.out.println();
- System.out.println("First Array: ");
- for (int e = 0; e < ray2.length; e++)
- {
- System.out.println(ray2[e]);
- if (ray2[e] < 0)
- {
- break;
- }
- }
- System.out.println();
- System.out.println("Second Array: ");
- for (int e = 0; e < sting2.length; e++)
- {
- System.out.println(sting2[e]);
- if (sting2[e] < 0)
- {
- break;
- }
- }
- int [] temp2 = {0};
- int [] combined2 = new int [(count1 + count2 - 2)];
- for (int w = 0; w < count2 + count1 - 2; w++)
- {
- if (combined[w - 1]<combined[w])
- combined[w] = combined2[w];
- else
- {
- temp2[w]= combined[w];
- combined2[w] = combined[w - 1];
- combined2[w - 1] = temp2[w];
- }
- }
- System.out.println();
- System.out.println("Merged Array: ");
- for (int e = 0; e < ray2.length + sting2.length; e++)
- {
- System.out.println(combined2[e]);
- if (combined2[e] < 0)
- {
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement