/
Pavlovich.A.M
/
Matrix
Обзор
Документация
Войти
/
Pavlovich.A.M
/
Matrix
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
MatrixRotation.java
47 строк
1 KB
Pavlovich.A.M
upload files
01 мар 2026, 10:56
Верифицирован
01 мар 2026, 10:56
4b87909
Код
Авторство
О чём код?
import java.util.Random; public class MatrixRotation { public static final int SIZE = 8; public static void main(String[] args) { int[][] colors = new int[SIZE][SIZE]; Random random = new Random(); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(256); } } System.out.println("Исходная матрица:"); printMatrix(colors); int[][] rotatedColors = rotateMatrix(colors); System.out.println("\nМатрица после поворота на 90 градусов по часовой стрелке:"); printMatrix(rotatedColors); } public static void printMatrix(int[][] matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { // %4d выделяет 4 знака под каждое число для ровной таблицы System.out.format("%4d", matrix[i][j]); } System.out.println(); } } public static int[][] rotateMatrix(int[][] matrix) { int[][] rotated = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotated[i][j] = matrix[SIZE - 1 - j][i]; } } return rotated; } }