@@ -0,0 +1,1846 @@
+package mergesort;%0Aimport java.util.Arrays;%0A%0Apublic class MergeSort %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D unsortedArray;%0A        int%5B%5D sortedArray;%0A        unsortedArray = new int%5B%5D %7B6,7,54,8,6,4,0,342,5,3,32,34,5,32,1,34,46,46,32,13,32,34,35,-654%7D;%0A        sortedArray = mergeSort(unsortedArray);%0A                %0A        for (int element : sortedArray) %7B%0A            System.out.print(element + %22 %22);%0A        %7D%0A    %7D%0A%0A    public static int%5B%5D mergeSort(int%5B%5D unsortedArray) %7B%0A        // recursive merge sort algorithm%0A        int inputLength = unsortedArray.length;%0A%0A        // split array into 2 arrays that diff by %3C= 1%0A        int%5B%5D arrayA = Arrays.copyOfRange(unsortedArray, 0, inputLength/2);%0A        int%5B%5D arrayB = Arrays.copyOfRange(unsortedArray, inputLength/2, inputLength);%0A        int%5B%5D sortedArray = new int%5BinputLength%5D;%0A        %0A        // continue to split arrays until they are both diff by %3C= 1%0A        if (arrayA.length %3E 1 %7C%7C arrayB.length %3E 1)%7B%0A            arrayA = mergeSort(arrayA);%0A            arrayB = mergeSort(arrayB);%0A        %7D%0A        %0A        int i = 0;%0A        int j = 0;%0A        for (int k=0; k%3CinputLength; k++)%7B%0A            // if 1 array is already used up just keep adding other array);%0A            if (i==arrayA.length)%7B%0A                sortedArray%5Bk%5D = arrayB%5Bj%5D;%0A                j++;%0A                continue;%0A            %7D else if (j==arrayB.length)%7B%0A                sortedArray%5Bk%5D = arrayA%5Bi%5D;%0A                i++;%0A                continue;%0A            %7D%0A            %0A            // add the lesser array element to the sorted array%0A            if (arrayA%5Bi%5D %3C arrayB%5Bj%5D)%7B%0A                sortedArray%5Bk%5D = arrayA%5Bi%5D;%0A                i++;%0A            %7D else %7B%0A                sortedArray%5Bk%5D = arrayB%5Bj%5D;%0A                j++;%0A            %7D%0A        %7D%0A%0A        return sortedArray;%0A    %7D%0A%7D

change print for loop to foreach