/
ARTEMEV_ROMAN
/
netologia_hw6
Обзор
Документация
Войти
/
ARTEMEV_ROMAN
/
netologia_hw6
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
74 строки
3 KB
ARTEMEV_ROMAN
Домашнее задание 6
15 ноя 2025, 17:11
15 ноя 2025, 17:11
0916297
Код
Авторство
О чём код?
import java.util.Random; import java.util.Scanner; public class Main { public static final int SIZE = 3; public static void main(String[] args) { Random random = new Random(); Scanner scanner = new Scanner(System.in); int[][] colors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(0, 256); } } System.out.println("Выведи матрицу до поворота: "); printArray(colors); System.out.println("Введи угол поворота, на который хочешь повернуть матрицу: 90, 180, 270 градусов"); String input = scanner.nextLine(); int corner = Integer.parseInt(input); if (corner == 90) { printArrayOn90Degrees(colors); } else if (corner == 180) { printArrayOn180Degrees(colors); } else if (corner == 270) { printArrayOn270Degrees(colors); } else { System.out.println("Введен неправильный угол поворота!"); } } public static void printArray(int[][] colors) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.print(colors[i][j] + " "); } System.out.println(); } } public static void printArrayOn90Degrees(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[j][SIZE - i - 1] = colors[i][j]; } } System.out.println("Выведи матрицу после поворота на 90 градусов (по часовой стрелке): "); printArray(rotatedColors); } public static void printArrayOn180Degrees(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[SIZE - i - 1][SIZE - j - 1] = colors[i][j]; } } System.out.println("Выведи матрицу после поворота на 180 градусов (по часовой стрелке): "); printArray(rotatedColors); } public static void printArrayOn270Degrees(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[SIZE - j - 1][i] = colors[i][j]; } } System.out.println("Выведи матрицу после поворота на 270 градусов (по часовой стрелке): "); printArray(rotatedColors); } }