/
Pavel23
/
HW8
Обзор
Документация
Войти
/
Pavel23
/
HW8
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
65 строк
2 KB
Pavel23
upload files
19 окт 2025, 12:16
19 окт 2025, 12:16
6f1ba2d
Код
Авторство
О чём код?
import java.util.Random; import java.util.Scanner; public class Main { public static final int SIZE = 8; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); 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); } } printColors(colors); System.out.print("Введите угол поворота (90, 180, 270): "); int input = scanner.nextInt(); int[][] rotatedColors = new int[SIZE][SIZE]; if (input == 90) rotatedColors = rotate90(colors); else if (input == 180) rotatedColors = rotate180(colors); else if (input == 270) rotatedColors = rotate270(colors); System.out.println(); printColors(rotatedColors); } public static int[][] rotate90(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[(SIZE - 1) - j][i]; } } return rotatedColors; } public static int[][] rotate180(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[(SIZE - 1) - i][(SIZE - 1) - j]; } } return rotatedColors; } public static int[][] rotate270(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[j][(SIZE - 1) - i]; } } return rotatedColors; } public static void printColors(int[][] colors) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.format("%4d", colors[i][j]); } System.out.println(); } } }