/
AlekseyVologzhin
/
ArrayMultidimensional
Обзор
Документация
Войти
/
AlekseyVologzhin
/
ArrayMultidimensional
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Matrix.java
68 строк
2 KB
AlekseyVologzhin
upload files
23 мар 2025, 17:24
23 мар 2025, 17:24
c2bec30
Код
Авторство
О чём код?
import java.util.Random; public class Matrix { public static final int SIZE = 8; public static void main(String[] args) { Random random = new Random(); int[][] colors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(256); } } System.out.println("Обычная матрица: \n"); printColors(colors); int[][] rotatedColors = turnColors(colors, 90); System.out.println("Повернутая матрица: \n"); printColors(rotatedColors); } public static void printColors(int[][] colors) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.printf("%4d", colors[i][j]); } System.out.println(); } System.out.println(); } private static int[][] turnColors(int[][] colors) { int[][] turn = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { turn[i][j] = colors[j][SIZE - 1 - i]; } } return turn; } private static int[][] turnColors(int[][] colors, int angle) { int[][] turn = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { switch (angle) { case 90: turn[i][j] = colors[SIZE - 1 - j][i]; break; case 180: turn[i][j] = colors[SIZE - 1 - i][SIZE - 1 - j]; break; case 270: turn[i][j] = colors[j][SIZE - 1 - i]; break; default: turn[i][j] = colors[i][j]; break; } } } return turn; } }