/
Shcod
/
java-hw-arrays2
Обзор
Документация
Войти
/
Shcod
/
java-hw-arrays2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/Main.java
75 строк
2 KB
Shcod
first commit
03 авг 2026, 05:26
03 авг 2026, 05:26
d631027
Код
Авторство
О чём код?
import java.util.Random; public class Main { public static final int SIZE = 8; public static void main(String[] args) { int[][] colors = new int[SIZE][SIZE]; Random random = new Random(); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { colors[i][j] = random.nextInt(256); } } System.out.println("_______________________________________"); printMatrix(colors); System.out.println("_____________________________________90"); printMatrix(rotate90(colors)); System.out.println("_____________________________________180"); printMatrix(rotate180(colors)); System.out.println("_____________________________________270"); printMatrix(rotate270(colors)); } 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(); } } public static int[][] rotate90(int[][] colors) { 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; } // // Прямая формула для 180° // public static int[][] rotate180(int[][] colors) { // int n = colors.length; // int[][] result = new int[n][n]; // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // result[i][j] = colors[n - 1 - i][n - 1 - j]; // } // } // return result; // } // // // Прямая формула для 270° (или -90°) // public static int[][] rotate270(int[][] colors) { // int n = colors.length; // int[][] result = new int[n][n]; // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // result[i][j] = colors[j][n - 1 - i]; // } // } // return result; // } public static int[][] rotate180(int[][] colors) { return rotate90(rotate90(colors)); } public static int[][] rotate270(int[][] colors) { return rotate180(rotate90(colors)); } }