Java Matrix Flip flipLeftToRight(int[][] theArray)

Here you can find the source of flipLeftToRight(int[][] theArray)

Description

flip the block from left to right

License

Open Source License

Parameter

Parameter Description
theArray theArray the original block content as matrix

Declaration

public static int[][] flipLeftToRight(int[][] theArray) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w  w  w  .  j av  a  2s  .  c  o  m*/
     * flip the block from left to right
     * @param theArray theArray the original block content as matrix
     * @return
     */
    public static int[][] flipLeftToRight(int[][] theArray) {

        for (int i = 0; i < theArray.length; i++) {
            for (int curr = 0; curr < (theArray[0].length + 1) / 2; curr++) {

                int saved = theArray[i][curr];
                theArray[i][curr] = theArray[i][theArray[0].length - 1 - curr];
                theArray[i][theArray[0].length - 1 - curr] = saved;
            }
        }
        return theArray;
    }
}

Related

  1. flipInPlace(int[][] theArray)
  2. flipLR(int[][] x)
  3. flipOverX(T[][] arr)
  4. flipOverY(T[][] arr)