/
xtasy
/
HW_ARR2D
Обзор
Документация
Войти
/
xtasy
/
HW_ARR2D
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Main.java
71 строка
2 KB
xtasy
init
24 фев 2026, 18:06
24 фев 2026, 18:06
a470900
Код
Авторство
О чём код?
import java.util.Random; public class Main { public static final int SIZE = 8; public static void main(String[] args) { int[][] colors = new int[SIZE][SIZE]; Random random = new Random(); for (int[] arrColors : colors) { for (int i = 0; i < SIZE; i++) { arrColors[i] = random.nextInt(256); } } printColors(colors); System.out.println("Поворот на 90 градусов по часовой стрелке"); printColors(rotateClockwise90(colors)); System.out.println("Поворот на 180 градусов по часовой стрелке"); printColors(rotateClockwise180(colors)); System.out.println("Поворот на 270 градусов по часовой стрелке"); printColors(rotateClockwise270(colors)); } private static int[][] rotateClockwise270(int[][] colors) { int[][] temp = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { temp[i][j] = colors[j][SIZE - i - 1]; } } return temp; } private static int[][] rotateClockwise180(int[][] colors) { int[][] temp = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { temp[i][j] = colors[SIZE - i - 1][SIZE - j - 1]; } } return temp; } public static int[][] rotateClockwise90(int[][] colors) { int[][] temp = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { temp[i][j] = colors[SIZE - j - 1][i]; } } return temp; } public static void printColors(int[][] colors) { for (int[] arrColors : colors) { for (int i = 0; i < SIZE; i++) { System.out.printf("%4d", arrColors[i]); } System.out.println(); } } }