willieshi232

Untitled

Dec 9th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import java.util.*;
  2. public class swapALL
  3. {
  4. public static void main(String [] args)
  5. {
  6. int[] mudkip = {12, 34, 56};
  7. int[] marshstomp = {20, 50, 80};
  8. swapALL(mudkip, marshstomp);
  9. System.out.println(Arrays.toString(mudkip));
  10. System.out.println(Arrays.toString(marshstomp));
  11. }
  12. public static void swapALL(int[] mudkip, int[] marshstomp)
  13. {
  14. int[] temp = new int[mudkip.length];
  15. for(int i = 0; i < temp.length; i++)
  16. {
  17. temp[i] = mudkip[i];
  18.  
  19. }
  20. for(int i = 0; i < temp.length; i++)
  21. {
  22. mudkip[i] = marshstomp[i];
  23.  
  24. }
  25. for(int i = 0; i < temp.length; i++)
  26. {
  27. marshstomp[i] = temp[i];
  28.  
  29. }
  30. }
  31. }
  32.  
  33. import java.util.*;
  34. public class Merge
  35. {
  36. public static void main(String [] args)
  37. {
  38. int[] a1 ={12, 34, 56};
  39. int[] a2= {7, 8, 9, 10};
  40. int[] a3 = merge(a1, a2);
  41. System.out.println(Arrays.toString(a3));
  42. }
  43. public static int[] merge(int[] a1, int[] a2)
  44. {
  45. int[] a3 = new int[a1.length + a2.length];
  46. int count = 0;
  47. for(int i = 0; i < a1.length; i++)
  48. {
  49. a3[i] = a1[i];
  50. count++;
  51. }
  52. for(int x = 0; x < a2.length; x++)
  53. {
  54. a3[count] = a2[x];
  55. count++;
  56. }
  57. return a3;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment