/
Yuretz78
/
MatrixRotation
Обзор
Документация
Войти
/
Yuretz78
/
MatrixRotation
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
MatrixRotation.java
62 строки
2 KB
Yuretz78
create: MatrixRotation.java
01 май 2026, 12:43
Верифицирован
01 май 2026, 12:43
37e15c2
Код
Авторство
О чём код?
import java.util.Random; import java.util.Scanner; public class MatrixRotation { public static final int SIZE = 8; public static void main(String[] args) { int[][] matrix = generateMatrix(); System.out.println("Исходная матрица:"); printMatrix(matrix); int[][] rotated90 = rotate90(matrix); System.out.println("\nМатрица после поворота на 90 градусов:"); printMatrix(rotated90); Scanner scanner = new Scanner(System.in); System.out.print("\nВведите угол поворота (90, 180 или 270): "); int angle = scanner.nextInt(); int[][] rotated = rotateMatrix(matrix, angle); System.out.println("\nМатрица после поворота на " + angle + " градусов:"); printMatrix(rotated); } public static int[][] generateMatrix() { Random random = new Random(); int[][] matrix = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { matrix[i][j] = random.nextInt(256); } } return matrix; } public static void printMatrix(int[][] matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.format("%4d", matrix[i][j]); } System.out.println(); } } public static int[][] rotate90(int[][] matrix) { int[][] rotated = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotated[j][SIZE - 1 - i] = matrix[i][j]; } } return rotated; } public static int[][] rotateMatrix(int[][] matrix, int angle) { int[][] result = matrix; int rotations = angle / 90 % 4; for (int k = 0; k < rotations; k++) { result = rotate90(result); } return result; } }