Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ProgProj06_mc {
  3. public static void main(String[] args) {
  4. Scanner keyboard = new Scanner(System.in);
  5. int arr1 [] = new int [10000];
  6. int arr2 [] = new int [10000];
  7. int arr3 [] = new int [20000];
  8. int a = 0, b = 0, c = 0, num;
  9. boolean order = true;
  10.  
  11. System.out.println("Enter the values for the first array, up to 10000 values, enter a negative number to quit");
  12. num = keyboard.nextInt();
  13. while(num > 0) {
  14. arr1[a++] = num;
  15. num = keyboard.nextInt();
  16. if(arr1[a] > arr1[a + 1])
  17. order = false; }
  18.  
  19. System.out.println("Enter the values for the second array, up to 10000 values, enter a negative number to quit");
  20. num = keyboard.nextInt();
  21. while(num > 0) {
  22. arr2[b++] = num;
  23. num = keyboard.nextInt();
  24. if(arr2[b] > arr2[b + 1])
  25. order = false; }
  26.  
  27. if(order) {
  28. System.out.println("First Array:");
  29. for(int count = 0; count < a; count++)
  30. System.out.print(arr1[count] + " ");
  31.  
  32. System.out.println("\nSecond Array:");
  33. for(int count = 0; count < b; count++)
  34. System.out.print(arr2[count] + " ");
  35. a = 0;
  36. b = 0;
  37. while(arr1[a] >= 0 || arr2[b] >= 0) {
  38.  
  39. if(arr2[b] < 0 || (arr1[a] >= 0 && arr1[a] < arr2[b]))
  40. arr3[c++] = arr1[a++];
  41. else
  42. arr3[c++] = arr2[b++]; }
  43.  
  44. System.out.println("Merged Array:");
  45. for(int count = 0; count < c; count++)
  46. System.out.print(arr3[count] + " ");
  47. System.out.println("\n"); }
  48. else
  49. System.out.println("ERROR: Array not in correct order");
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement