/
beks89
/
Homework7.1
Обзор
Документация
Войти
/
beks89
/
Homework7.1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Main.java
55 строк
2 KB
beks89
upload files
20 мар 2025, 20:15
20 мар 2025, 20:15
3031991
Код
Авторство
О чём код?
import javax.swing.*; import java.util.Random; import java.util.Scanner; 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); } } Scanner scanner = new Scanner(System.in); int[][] result = rotatedMatrix(colors); while (true) { System.out.println("Сформирована матрица 8х8"); printField(colors); System.out.println("Перевернуть на 90 градусов?"); System.out.println("да или нет"); String input = scanner.nextLine(); if (("да".equals(input))) { printField(colors); System.out.println(); printField(result); System.out.println("Ваша матрица перевёрнута на 90 градусов"); break; } else { System.out.println("Матрица не перевёрнута"); break; } } } public static void printField(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[][] rotatedMatrix(int[][] rotatedColors) { int[][] result = new int[SIZE][SIZE]; for (int i = 0; i < rotatedColors.length; i++) { for (int j = 0; j < rotatedColors[i].length; j++) { result[j][i] = rotatedColors[SIZE - 1 - i][j]; } } return result; } }