/
maksh
/
hw7
Обзор
Документация
Войти
/
maksh
/
hw7
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Main.java
70 строк
2 KB
maksh
upload files
25 май 2025, 16:25
25 май 2025, 16:25
400f239
Код
Авторство
О чём код?
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]; int[][] rotatedColors = new int[SIZE][SIZE]; Scanner scanner = new Scanner(System.in); Random random = new Random(); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(256); } } printMatrix(colors); while (true) { System.out.println("Введите градус поворота (90, 180, 270) или end: "); String input = scanner.nextLine(); if ("end".equals(input)) { System.out.println("Приходите в следующий раз! До свидания!"); break; } int degree = Integer.parseInt(input); int[][] resultMatrix = turnMatrix(rotatedColors, colors, degree); printMatrix(resultMatrix); } } public static void printMatrix(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(); } System.out.println(); } public static int[][] turnMatrix(int[][] rotatedColors, int[][] colors, int degree) { if (degree == 90) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[SIZE - 1 - j][i]; } } return rotatedColors; } if (degree == 180) { 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; } if (degree == 270) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[i][j] = colors[j][SIZE - 1 - i]; } } return rotatedColors; } System.out.println("Укажите верный градус! Вот наша начальная матрица:"); return colors; } }