@@ -0,0 +1,2576 @@
+//package fromslides.S15;%0A%0A/**%0A * Create a 2d array, sum it%0A *%0A * @author     pmc%0A * @version    slide deck 15%0A */%0A%0Apublic class ArrayTranspose %7B%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D%5B%5D a = %7B%0A            %7B 0,1,3,2 %7D, %0A            %7B 1,4,8,7%7D, %0A            %7B 9, 7,0,3 %7D%0A        %7D;%0A        int%5B%5D%5B%5D b = %7B%0A            %7B 0,1,3,2 %7D, %0A            %7B 1,4,8,7, 5, 6 %7D, %0A            %7B 9, 7,0,3 %7D%0A        %7D;%0A        int  transposedArray%5B%5D%5B%5D;%0A%0A        transposedArray = transpose(a);%0A        displayArray(%22Original %22, a);%0A        displayArray(%22Transposed %22, transposedArray);%0A        %0A        if (transposedArray == null)%0A            System.out.println(%22Original Array is not rectangular%22);%0A        else displayArray(%22Transposed %22, transposedArray); %0A%0A        transposedArray = transpose(b);%0A        displayArray(%22Original %22, b);%0A        %0A        if (transposedArray == null)%0A            System.out.println(%22%5CnOriginal Array is not rectangular%22);%0A        else displayArray(%22Transposed %22, transposedArray); %0A%0A        %7D // end main%0A    public static int%5B%5D%5B%5D transpose (int%5B%5D%5B%5D array) %7B%0A           //check if rectangular  %E2%80%8B%0A            int col = array%5B0%5D.length;%0A            for (int i = 1; i%3C array.length; i++)%0A                %7B%0A                    if (array%5Bi%5D.length != col)%0A                        return null;%0A                %7D%0A        // if we get here it must be rectangular so transpose%E2%80%8B%0A           int%5B%5D%5B%5D t = new int%5Barray%5B0%5D.length%5D%5Barray.length%5D;%0A           for (int i = 0; i %3C t.length; i ++)%0A                    %7B%0A                        for (int j=0; j%3C t%5Bi%5D.length; j++)%0A                            t%5Bi%5D%5Bj%5D = array%5Bj%5D%5Bi%5D;%0A                    %7D%0A                    return t;%0A                    %7D%0A/**%0A        * display the array with a message %0A        * @param name   message String  integer array%0A        * @param arry    integer array%0A        **/ %0Apublic static void displayArray(String name, int arry%5B%5D)   %7B%0A    System.out.println(%22%5CnArray: %22+name);%0A    for (int i=0; i %3C arry.length; i++)%0A     System.out.print(%22%5B%22+i+%22%5D = %22+ arry%5Bi%5D+%22 %22);%0A%7D%0A/**%0A        * display the array with a message %0A        * @param name   message String  integer array%0A        * @param arry    integer array%0A        **/ %0Apublic static void displayArray(String name, int arry%5B%5D%5B%5D)   %7B%0A    System.out.println(%22%5CnArray: %22+name);%0A    for (int row=0; row %3C arry.length; row++)   %7B%0A        System.out.printf(%22%5B %22);%0A       for (int col = 0; col %3C arry%5Brow%5D.length; col++ )%0A             System.out.print(arry%5Brow%5D%5Bcol%5D +%22 %22);%0A         System.out.printf(%22%5D%5Cn%22);%0A     %7D%0A%7D%0A%7D // end class%0A

add matrix transpose