Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
846 B
1
Indexable
Never
	public static void main(String[] args) {
		int[][] genMatrix = generateMatrix(6);
		print(genMatrix); //to tylko wyświetla tablicę
	}


	private static int[][] generateMatrix(int dim) {
		int[][] matrix = new int[dim][dim];
		int currValue = 1;

		for (int i = 0; i < dim; i++) {
			for (int j = 0; j < dim; j++) {
				if (matrix[i][j] == 0) {
					matrix[i][j] = currValue;
					currValue = currValue + 1;
					i = 0;
					j = 0;
				}
			}
			matrix = rotate(matrix);
		}
		return matrix;
	}

	private static int[][] rotate(int[][] matrix) {
		int matrixDimension = matrix.length;
		int[][] rotatedMatrix = new int[matrixDimension][matrixDimension];

		for (int i = 0; i < matrixDimension; i++) {
			for (int j = 0; j < matrixDimension; j++) {
				rotatedMatrix[i][j] = matrix[j][matrixDimension - 1 - i];
			}
		}
		return rotatedMatrix;
	}
Leave a Comment