matrix rotate Counter Clock Wise - Java java.lang

Java examples for java.lang:Math Matrix

Description

matrix rotate Counter Clock Wise

Demo Code


//package com.java2s;

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

Related Tutorials