/
SamMih
/
HOMEWORK6_matrix
Обзор
Документация
Войти
/
SamMih
/
HOMEWORK6_matrix
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
80 строк
3 KB
SamMih
HOMEWORK6_matrix
17 июн 2025, 11:23
17 июн 2025, 11:23
68c1801
Код
Авторство
О чём код?
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]; Random random = new Random(); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(256); } } System.out.println("Исходная матрица"); System.out.println(); printField(colors); int[][] rotatedColors = new int[SIZE][SIZE]; Scanner scanner = new Scanner(System.in); System.out.println("На сколько градусов повернуть матрицу?"); System.out.println("1 - 90 градусов"); System.out.println("2 - 180 градусов"); System.out.println("3 - 270 градусов"); String input = scanner.nextLine(); int operation = Integer.parseInt(input); switch (operation) { case 1: for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[j][SIZE - 1 - i] = colors[i][j]; } } System.out.println(); System.out.println("Матрица после поворота на 90 градусов"); System.out.println(); printField(rotatedColors); break; case 2: for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[SIZE -1 - i][SIZE - 1 - j] = colors[i][j]; } } System.out.println(); System.out.println("Матрица после поворота на 180 градусов"); System.out.println(); printField(rotatedColors); break; case 3: for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[SIZE -1 - j][i] = colors[i][j]; } } System.out.println(); System.out.println("Матрица после поворота на 270 градусов"); System.out.println(); printField(rotatedColors); break; } } public static void printField(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(); } } }