Created
October 2, 2023 17:37
-
-
Save rebekah/57318391b084d1e163a974da0c049793 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MergeArrays { | |
public static void main(String[] args) { | |
int[][] arrays = {{1,2,3},{14,15,16,17}}; | |
int mergedArrayLen = arrays[0].length + arrays[1].length; | |
int[] mergedArray = new int[mergedArrayLen]; | |
int mergedArrayIndex = 0; | |
for(int i = 0; i < arrays.length; i++){ | |
for(int j = 0; j < arrays[i].length; j++) { | |
mergedArray[mergedArrayIndex] = arrays[i][j]; | |
mergedArrayIndex++; | |
} | |
} | |
for(int num: mergedArray){ | |
System.out.print(num + " "); | |
} | |
System.out.println(" "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment