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, c = 0, num;
- boolean order = true;
- 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();
- if(arr1[a] > arr1[a + 1])
- order = false; }
- 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();
- if(arr2[b] > arr2[b + 1])
- order = false; }
- if(order) {
- 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] + " ");
- a = 0;
- b = 0;
- while(arr1[a] >= 0 || arr2[b] >= 0) {
- if(arr2[b] < 0 || (arr1[a] >= 0 && arr1[a] < arr2[b]))
- arr3[c++] = arr1[a++];
- else
- arr3[c++] = arr2[b++]; }
- System.out.println("Merged Array:");
- for(int count = 0; count < c; count++)
- System.out.print(arr3[count] + " ");
- System.out.println("\n"); }
- else
- System.out.println("ERROR: Array not in correct order");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement