/
MikhailKrasnosheev
/
HW7
Обзор
Документация
Войти
/
MikhailKrasnosheev
/
HW7
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Main.java
61 строка
2 KB
MikhailKrasnosheev
upload files
24 мар 2025, 14:31
24 мар 2025, 14:31
6b2b638
Код
Авторство
О чём код?
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 < colors.length; i++) { for (int j = 0; j < colors.length; j++) { colors[i][j] = random.nextInt(256); } } printMatrixs(colors); System.out.println(); Scanner scanner = new Scanner(System.in); System.out.print("Введите угол поворота матрицы: 90 , 180 или 270: "); String input = scanner.nextLine(); int operation = Integer.parseInt(input); int[][] rotateColors = new int[SIZE][SIZE]; for (int i = 0; i < rotateColors.length; i++) { for (int j = 0; j < rotateColors.length; j++) { switch (operation) { case 90: rotateColors[i][j] = colors[SIZE - (j + 1)][i]; break; case 180: rotateColors[i][j] = colors[SIZE - (i + 1)][SIZE - (j + 1)]; break; case 270: rotateColors[SIZE - (j + 1)][i] = colors[i][j]; break; case 0, 360, 720: rotateColors[i][j] = colors[i][j]; default: break; } } } printMatrixs(rotateColors); } public static void printMatrixs(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(); } } }