matrix rotate 180 degrees - Java java.lang

Java examples for java.lang:Math Matrix

Description

matrix rotate 180 degrees

Demo Code


//package com.java2s;

public class Main {
    public static boolean[][] rotate180degrees(boolean[][] matrix) {
        final int height = matrix.length;
        final int width = matrix[0].length;
        boolean[][] ret = new boolean[height][width];
        for (int verticalIndex = 0; verticalIndex < height; verticalIndex++) {
            for (int horizontalIndex = 0; horizontalIndex < width; horizontalIndex++) {
                ret[height - 1 - verticalIndex][width - 1 - horizontalIndex] = matrix[verticalIndex][horizontalIndex];
            }/*from  w w  w.  j a v  a 2 s  .  c om*/
        }
        return ret;
    }
}

Related Tutorials