
package TwoDimArrayOne;
public class TwoDimArrayEx3 {
	public int[][] reverse(int[][] theArray) {
		int[][] result;
		
		// Creating new array with same dimensions as param
		result = new int[theArray.length][];
		for (int row=0; row<result.length; row++) {
			result[row] = new int[theArray[row].length];
		}
		
		int resRow=0, resCol;
		for (int row=result.length-1; row>=0; row--,resRow++) {
			resCol = 0;
			for (int col=theArray[row].length - 1; col>=0; col--) {
				result[resRow][resCol++] = theArray[row][col];
			}	
		}
		
		return result;
	}
	
	public void printArray(int[][] array) {
		for (int row=0; row<array.length; row++) {
			for (int col=0; col<array[row].length; col++) {
				System.out.print(array[row][col] + " "); 
			}
			System.out.println();
		}
	}
	
	public TwoDimArrayEx3() {
		int[][] scores = {{5,7,4}, {9,3,2}};
		
		printArray(scores);
		System.out.println("Reverse");
		printArray(reverse(scores));
	}
	
	public static void main(String[] args) {
		new TwoDimArrayEx3();
	}
}
