/
conann
/
test7
Обзор
Документация
Войти
/
conann
/
test7
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Main.java
67 строк
2 KB
Kirill Opra
test7
04 мар 2025, 04:38
04 мар 2025, 04:38
de209c9
Код
Авторство
О чём код?
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 = generateMatrix(SIZE, SIZE); System.out.println("Исходная матрица: "); showMatrix(colors); System.out.println("Введите угол поворота (90, 180 или 270):"); Scanner scanner = new Scanner(System.in); int angle = scanner.nextInt(); int[][] rotatedMatrix = rotateRightMatrix(colors, angle); System.out.println("\nПеревернутая матрица: " + angle + " градусов"); showMatrix(rotatedMatrix); } private static int[][] generateMatrix(int rows, int columns) { Random random = new Random(); int[][] result = new int[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { result[i][j] = random.nextInt(256); } } return result; } private static void showMatrix(int[][] colors) { for (int i = 0; i < colors.length; i++) { for (int j = 0; j < colors[i].length; j++) { System.out.format("%4d", colors[i][j]); } System.out.println(); } } private static int[][] rotateRightMatrix(int[][] colors, int angle) { int size = colors.length; int[][] result = new int[size][size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { switch (angle) { case 90: result[i][j] = colors[size - 1 - j][i]; break; case 180: result[i][j] = colors[size - 1 - i][size - 1 - j]; break; case 270: result[size - 1 - j][i] = colors[i][j]; break; default: result[i][j] = colors[i][j]; } } }return result; } }