/
kubkut
/
hw0
Обзор
Документация
Войти
/
kubkut
/
hw0
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Matrix.java
79 строк
2 KB
kubkut
Добрый вечер! Матрица - дз
12 янв 2026, 20:46
12 янв 2026, 20:46
3d7ab45
Код
Авторство
О чём код?
import java.util.Random; import static java.lang.Integer.SIZE; public class Matrix { static final int SIZE = 8; public static void main(String[] args) { int [] [] colors = createColors(SIZE, SIZE); System.out.println("Оригинальная матрица "); printColors(colors); int [] [] result = rotateColors (colors, 270); System.out.println("Перевернутая матрица"); printColors (result); } // ниже задача 2 - необязательная. Закомментил основную private static int[][] rotateColors(int[][] colors, int angle) { int size = colors.length; int [] [] result = new int[size][size]; for (int i = 0; i < size; i ++) { for (int j = 0; j < size; j++) { switch (angle) { case 90: result[i][j] = colors [size - 1 - j][size - 1 - i]; break; case 180: result[i][j] = colors [size - 1 - i][size - 1 - j]; break; case 270: result [size - 1 - j][i] = colors [j][i] ; break; default: result[i][j] = colors [i] [j]; } } } return result; // private static int[][] rotateColors(int[][] colors) { // int size = colors.length; // int [] [] result = new int[size][size]; // // for (int i = 0; i < size; i ++) { // for (int j = 0; j < size; j++) { // result[i][j] = colors [size - 1 - j][i]; // } // } // return result; } public static void printColors (int[][] colors) { for (int i = 0; i < colors.length; i++) { for (int j = 0; j < colors[i].length; j++) { System.out.printf("%4d", colors [i][j]); } System.out.println(); } } private static int [][] createColors (int rows, int cols) { Random random = new Random (); int [] [] colors = new int [rows] [cols]; for (int i = 0; i < rows; i ++) { for (int j = 0; j < cols; j++) { colors [i] [j] = random.nextInt(256); } } return colors; } }