/
SofiMut
/
colorMatrix
Обзор
Документация
Войти
/
SofiMut
/
colorMatrix
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
67 строк
2 KB
SofiMut
upload files
31 май 2025, 06:14
31 май 2025, 06:14
4ef17d4
Код
Авторство
О чём код?
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]; getColors(colors); System.out.println("Матрица спектра цветов:"); printMatrix(colors); System.out.println(); Scanner scanner = new Scanner(System.in); System.out.println("На сколько градусов повернуть матрицу спектра: 90, 180 или 270?:"); String input = scanner.nextLine(); int degree = Integer.parseInt(input); int[][] newColors = rotateColors(colors, degree); System.out.println("Перевернутая матрица спектра цветов:"); printMatrix(newColors); } private static int[][] getColors(int[][] colors) { Random random = new Random(); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(256); } } return colors; } private static int[][] rotateColors(int[][] colors, int degree) { int[][] newColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { switch (degree) { case 90: newColors[i][j] = colors[SIZE - 1 - j][i]; break; case 180: newColors[i][j] = colors[SIZE - 1 - i][SIZE - 1 - j]; break; case 270: newColors[SIZE - 1 - j][i] = colors[i][j]; break; } } } return newColors; } public static void printMatrix(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(); } } }