// Two more method examples with arrays. The first concats two arrays, // The second takes two arrays and makes one hold the minimum values // and the other take the maximum values of each pair of values. import java.util.*; public class ArrayMethodExamples { public static void main(String[] args){ int[] a = {4, 6, 3, 5}; int[] b = {3, 7, 4, 4}; System.out.println("a = " + Arrays.toString(a)); System.out.println("b = " + Arrays.toString(b)); System.out.println(); int[] combined = concat(a, b); System.out.println("combined = " + Arrays.toString(combined)); System.out.println(); minMax(a, b); System.out.println("a = " + Arrays.toString(a)); System.out.println("b = " + Arrays.toString(b)); } // This method takes two int[]'s and creates one // bigger array that has all the values from a and b. public static int[] concat(int[] a, int[] b){ int[] concatArray = new int[a.length + b.length]; for(int i = 0; i < a.length; i++){ concatArray[i] = a[i]; } for(int i = 0; i < b.length; i++){ concatArray[a.length + i] = b[i]; } return concatArray; } // This method looks at two int arrays of the same length // and for each pair of elements between the two arrays, it // puts the minumum one in array a and the max in array b. public static void minMax(int[] a, int[] b){ for(int i = 0; i < a.length; i++){ if(a[i] > b[i]){ int temp = a[i]; a[i] = b[i]; b[i] = temp; } } } }