Advertisement
joseleonweb

Untitled

Aug 26th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. public class BarrejarArrays {
  2.  
  3.   public static void main(String[] args) {
  4.     int[] arrayA = {1, 3, 5, 7, 9, 11, 13, 15};
  5.     int[] arrayB = {2, 4, 6, 8, 10, 12, 14, 16};
  6.  
  7.     int[] nouArray = new int[arrayA.length + arrayB.length];
  8.  
  9.     //Omple la part de A.
  10.     int indexNou = 0;
  11.     for(int i = 0; i < arrayA.length; i++) {
  12.       nouArray[indexNou] = arrayA[i];
  13.       indexNou = indexNou + 2;
  14.     }
  15.     //Omple la part de B.
  16.     indexNou = 1;
  17.     for(int i = 0; i < arrayB.length; i++) {
  18.       nouArray[indexNou] = arrayB[i];
  19.       indexNou = indexNou + 2;
  20.     }
  21.     for(int i = 0; i < nouArray.length; i++) {
  22.       System.out.println(nouArray[i]);
  23.     }
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement