The document defines a JoinArrays class containing a main method that declares and initializes three integer arrays. It calls the joinArrays method, passing the three arrays, which returns a new array containing the concatenated contents of the input arrays. The main method then prints the resulting joined array. The joinArrays method calculates the length of the result, creates a new array, and copies each element of the input arrays into the result in order.
The document defines a JoinArrays class containing a main method that declares and initializes three integer arrays. It calls the joinArrays method, passing the three arrays, which returns a new array containing the concatenated contents of the input arrays. The main method then prints the resulting joined array. The joinArrays method calculates the length of the result, creates a new array, and copies each element of the input arrays into the result in order.
The document defines a JoinArrays class containing a main method that declares and initializes three integer arrays. It calls the joinArrays method, passing the three arrays, which returns a new array containing the concatenated contents of the input arrays. The main method then prints the resulting joined array. The joinArrays method calculates the length of the result, creates a new array, and copies each element of the input arrays into the result in order.
The document defines a JoinArrays class containing a main method that declares and initializes three integer arrays. It calls the joinArrays method, passing the three arrays, which returns a new array containing the concatenated contents of the input arrays. The main method then prints the resulting joined array. The joinArrays method calculates the length of the result, creates a new array, and copies each element of the input arrays into the result in order.
public static int[] joinArrays(int[] array1, int[] array2, int[] array3) { // Calculate the length of the resulting array int resultLength = array1.length+array2.length+array3.length;
// Create a new array to store the result
int[] result = new int[resultLength];
// Copy elements from array1 to result
for (int i = 0; i < array1.length; i++) { result[i] = array1[i]; }
// Copy elements from array2 to result
for (int i = 0; i < array2.length; i++) { result[array1.length + i] = array2[i]; }
// Copy elements from array3 to result
for (int i = 0; i < array3.length; i++) { result[array1.length + array2.length + i] = array3[i]; }
// Return the resulting array
return result; }
// Method to print an array
public static void printArray(int[] array) { for (int value : array) { System.out.print(value + " "); } System.out.println(); } }