title: How do I rotate a 3D matrix by 90 degrees counterclockwise?
body: <p>I'm trying to rotate a matrix counterclockwise by 90 degrees in Java. I found answers on how to do this with a 2D matrix, but my matrix is 3D.</p>
  
  <p>Here's how I found out on how to do a 2D rotation:</p>
  
  <pre><code>static int[][] rotateCW(int[][] mat) {
      final int M = mat.length;
      final int N = mat[0].length;
      int[][] ret = new int[N][M];
      for (int r = 0; r &lt; M; r++) {
          for (int c = 0; c &lt; N; c++) {
              ret[c][M-1-r] = mat[r][c];
          }
      }
      return ret;
  }
  </code></pre>
  
  <p>How would I go about rotating a 3D matrix then?</p>