Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ProgProj06_mc {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int arr1 [] = new int [10000];
- int arr2 [] = new int [10000];
- int arr3 [] = new int [20000];
- int a = 0, b = 0, num;
- System.out.println("Enter the values for the first array, up to 10000 values, enter a negative number to quit");
- num = keyboard.nextInt();
- while(num > 0) {
- arr1[a++] = num;
- num = keyboard.nextInt(); }
- System.out.println("Enter the values for the second array, up to 10000 values, enter a negative number to quit");
- num = keyboard.nextInt();
- while(num > 0) {
- arr2[b++] = num;
- num = keyboard.nextInt(); }
- for(int count = 0; count < a - 1; count++) {
- if(arr1[count] > arr1[count+1]) {
- System.out.println("ERROR: Array not in correct order");
- return; }}
- for(int count = 0; count < b - 1; count++) {
- if(arr2[count] > arr2[count+1]) {
- System.out.println("ERROR: Array not in correct order");
- return; }}
- System.out.println("First Array:");
- for(int count = 0; count < a; count++)
- System.out.print(arr1[count] + " ");
- System.out.println("\nSecond Array:");
- for(int count = 0; count < b; count++)
- System.out.print(arr2[count] + " ");
- int i1 = 0, i2 = 0, i3 = 0;
- while(arr1[i1] >= 0 || arr2[i2] >= 0)
- {
- if(arr2[i2] < 0 || (arr1[i1] >= 0 && arr1[i1] < arr2[i2]))
- arr3[i3++] = arr1[i1++];
- else
- arr3[i3++] = arr2[i2++];
- }
- System.out.println("Merged Array:");
- for(int count = 0; count < i3; count++)
- System.out.print(arr3[i3] + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement