/
Hatshess
/
Arrays_are_multidimensional
Обзор
Документация
Войти
/
Hatshess
/
Arrays_are_multidimensional
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Main.java
65 строк
2 KB
Hatshess
Загрузить файлы в «»
20 июл 2025, 13:19
20 июл 2025, 13:19
b5ada0d
Код
Авторство
О чём код?
import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class Main { public static final int SIZE = 8; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] colors = new int[SIZE][SIZE]; int[][] rotatedColors = 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); } } String team = sc.nextLine(); int[][] turn = rotateMatrix(colors, team); System.out.println("Дана матрица: "); result(colors); System.out.println("Перевёрнутая матрица: "); result(turn); } public static int[][] rotateMatrix(int [][] colors, String team) { int[][] rotatedMatrix = new int[colors.length][colors.length]; if(team.equals("1")){ for (int i = 0; i < colors.length; i++) { for (int j = 0; j < colors.length; j++) { rotatedMatrix[i][j] = colors[colors.length - j - 1][i]; } } }else if(team.equals("2")){ for (int i = 0; i < colors.length; i++) { for (int j = 0; j < colors.length; j++) { rotatedMatrix[i][j] = colors[colors.length - i - 1][colors.length - j - 1]; } } }else if(team.equals("3")){ for (int i = 0; i < colors.length; i++) { for (int j = 0; j < colors.length; j++) { rotatedMatrix[i][j] = colors[j][colors.length - i - 1]; } } }return rotatedMatrix; } public static void result(int[][]matrix){ System.out.println(); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.format("%4d", matrix[i][j]); } System.out.println(); } System.out.println(); } }