/
VladislavBasakevich
/
arrays2
Обзор
Документация
Войти
/
VladislavBasakevich
/
arrays2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Main.java
52 строки
1 KB
VladislavBasakevich
upload files
02 мар 2025, 17:11
02 мар 2025, 17:11
fc0ff25
Код
Авторство
О чём код?
import java.util.Random; public class Main { private static final int SIZE = 8; public static void main(String[] args) { int[][] colors = createMatrix(SIZE, SIZE); System.out.println("Изначальная матрица:"); printMatrix(colors); int[][] rotatedColors = resultMatrix(colors); System.out.println("Перевернутая матрица:"); printMatrix(rotatedColors); } private static int[][] resultMatrix(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; } private 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(); } } private static int[][] createMatrix(int SIZE, int size) { Random random = new Random(); int [][] result = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { result[i][j] = random.nextInt(256); } } return result; } }