/
beks89
/
Homework7
Обзор
Документация
Войти
/
beks89
/
Homework7
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Main.java
62 строки
2 KB
beks89
upload files
20 мар 2025, 11:40
20 мар 2025, 11:40
d419895
Код
Авторство
О чём код?
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[][] rotatedColors = new int[SIZE][SIZE]; 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); 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(); printField1(rotatedColors, colors); 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 void printField1(int[][] rotatedColors, int[][] colors) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[j][0] = colors[7][j]; rotatedColors[j][1] = colors[6][j]; rotatedColors[j][2] = colors[5][j]; rotatedColors[j][3] = colors[4][j]; rotatedColors[j][4] = colors[3][j]; rotatedColors[j][5] = colors[2][j]; rotatedColors[j][6] = colors[1][j]; rotatedColors[j][7] = colors[0][j]; System.out.format("%4d", rotatedColors[i][j]); } System.out.println(); } } }