/
Vickie
/
hw_matrix
Обзор
Документация
Войти
/
Vickie
/
hw_matrix
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
59 строк
2 KB
Vickie
Create: Main.java
25 июн 2026, 13:16
Верифицирован
25 июн 2026, 13:16
78afba1
Код
Авторство
О чём код?
import java.util.Random; import java.util.Scanner; public class Main { public static final int SIZE = 8; public static void main(String[] args) { int[][] colors = new int[SIZE][SIZE]; int[][] rotatedColors = new int[SIZE][SIZE]; Scanner input = new Scanner(System.in); Random random = new Random(); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(266); } } printMatrix(colors); System.out.println("На сколько градусов повернуть матрицу? (90, 180, 270)"); int angle = input.nextInt(); turnMatrix(colors, rotatedColors, angle); printMatrix(rotatedColors); } private static void turnMatrix(int[][] matrix, int[][] rotatedMatrix, int angle) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { switch (angle) { case 90: rotatedMatrix[i][j] = matrix[SIZE - j - 1][i]; break; case 180: rotatedMatrix[i][j] = matrix[SIZE - i - 1][SIZE - j - 1]; break; case 270: rotatedMatrix[i][j] = matrix[j][SIZE - i - 1]; break; } } } } private 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(); } } }