Tools Auto Format -- Error ?
in
Programming Questions
•
2 years ago
I copied this program in the Processing editor.
When I just do Tools: Auto Format on it, I get an error:
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Can you tell me what's wrong?
- //http://forum.processing.org/topic/rotating-a-2d-array
//http://stackoverflow.com/questions/2799755/rotate-array-clockwise
//rotate array - import java.util.Arrays;
- static void printMatrix(int[][] mat) {
System.out.println("Matrix = ");
for (int[] row : mat) {
System.out.println(Arrays.toString(row));
}
}
public static void main(String[] args){
int[][] mat = {
{ 1, 2, 3 }, { 4, 5, 6 }
};
printMatrix(mat);
// Matrix =
// [1, 2, 3]
// [4, 5, 6]
int[][] matCW = rotateCW(mat);
printMatrix(matCW);
// Matrix =
// [4, 1]
// [5, 2]
// [6, 3]
} - static int[][] rotateCW(int[][] mat) {
final int mlen1 = mat.length;
final int mlen2 = mat[0].length;
int[][] ret = new int[mlen2][mlen1];
for (int r = 0; r < mlen1; r++) {
for (int c = 0; c < mlen2; c++) {
ret[c][mlen1-1-r] = mat[r][c];
}
}
return ret;
}
1