Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class assignmentsix {
  4.  
  5.  
  6. @SuppressWarnings("null")
  7. public static void main(String[] args)
  8. {
  9.  
  10. Scanner scan = new Scanner(System.in);
  11. int count1 = 0;
  12. int count2 = 0;
  13. int temp = 0;
  14. int [] ray1 = new int [10000];
  15. int [] sting1 = new int [10000];
  16. System.out.println("Enter the values for the first array, up to 10000 values, enter a negative number to quit");
  17. for (int i = 0; i < ray1.length; i++)
  18. {
  19. ray1[i] = scan.nextInt();
  20. count1++;
  21. if (ray1[i] < 0)
  22. {
  23. break;
  24. }
  25. }
  26. System.out.println("Enter the values for the second array, up to 10000 values, enter a negative number to quit");
  27. for (int k = 0; k < sting1.length; k++)
  28. {
  29. sting1[k] = scan.nextInt();
  30. count2++;
  31. if (sting1[k] < 0)
  32. {
  33. break;
  34. }
  35. }
  36. //new array w/o 0's for ray
  37. int [] ray2 = new int [count1 - 1];
  38. for (int u = 0; u < count1 - 1; u++)
  39. {
  40. ray2[u] = ray1[u];
  41. }
  42. //new array w/o 0's for sting
  43. int [] sting2 = new int [count2 - 1];
  44. for (int o = 0; o < count2 - 1; o++)
  45. {
  46. sting2[o] = sting1[o];
  47. }
  48. int [] combined = new int [(count1 - 1) + (count2)];
  49. for (int z = 0; z < count1 - 1; z++)
  50. {
  51. combined[z] = ray2[z];
  52. }
  53. for (int x = count1 ; x < count2 + count1 - 2; x++)
  54. {
  55. combined[x] = sting2[x-count1];
  56. }
  57. System.out.println();
  58. System.out.println("First Array: ");
  59. for (int e = 0; e < ray2.length; e++)
  60. {
  61. System.out.println(ray2[e]);
  62. if (ray2[e] < 0)
  63. {
  64. break;
  65. }
  66. }
  67.  
  68. System.out.println();
  69. System.out.println("Second Array: ");
  70. for (int e = 0; e < sting2.length; e++)
  71. {
  72. System.out.println(sting2[e]);
  73. if (sting2[e] < 0)
  74. {
  75. break;
  76. }
  77. }
  78. int [] temp2 = {0};
  79. int [] combined2 = new int [(count1 + count2 - 2)];
  80. for (int w = 0; w < count2 + count1 - 2; w++)
  81. {
  82. if (combined[w - 1]<combined[w])
  83. combined[w] = combined2[w];
  84. else
  85. {
  86. temp2[w]= combined[w];
  87. combined2[w] = combined[w - 1];
  88. combined2[w - 1] = temp2[w];
  89. }
  90. }
  91. System.out.println();
  92. System.out.println("Merged Array: ");
  93. for (int e = 0; e < ray2.length + sting2.length; e++)
  94. {
  95. System.out.println(combined2[e]);
  96. if (combined2[e] < 0)
  97. {
  98. break;
  99. }
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement