/
h2r
/
Multidimensional_arrays
Обзор
Документация
Войти
/
h2r
/
Multidimensional_arrays
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
60 строк
2 KB
h2r
update Main.java
19 окт 2025, 15:58
19 окт 2025, 15:58
d0689ca
Код
Авторство
О чём код?
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]; Random random = new Random(); // Рандомное заполнение for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(256); } } Scanner sc = new Scanner(System.in); System.out.println("Введите угол поворота (90, 180, 270):"); int angle = sc.nextInt(); if (angle == 90) { for (int i = 0; i < SIZE; i++) { //Поворот матрицы на 90 градусов по часовой стрелке for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[SIZE - 1 - j][i]; } } } else if (angle == 180) { for (int i = 0; i < SIZE; i++) { //Поворот матрицы на 180 градусов по часовой стрелке for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[SIZE - 1 - i][SIZE - 1 - j]; } } } else if (angle == 270) { for (int i = 0; i < SIZE; i++) { //Поворот матрицы на 270 градусов по часовой стрелке for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[j][SIZE - 1 - i]; } } } else { System.out.println("Введены некорректные данные"); return; } System.out.println("\n Исходная матрица: \n"); printMatrix(colors); System.out.println("\n Поворот матрица на: " + angle + " градусов. \n"); printMatrix(rotatedColors); } 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(); } } }