/
imovannanis
/
ArraysHW
Обзор
Документация
Войти
/
imovannanis
/
ArraysHW
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
patch
Main.java
81 строка
2 KB
imovannanis
upload reformat code
03 май 2025, 18:31
03 май 2025, 18:31
660b393
Код
Авторство
О чём код?
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 sc = new Scanner(System.in); System.out.println("Вот матрица: "); printField(colors); while (true) { System.out.println("Выберите градус поворота: 90, 180 или 270. Для завершения работы введите end"); String input = sc.nextLine(); if (input.equals("end")) { break; } int degree = Integer.parseInt(input); switch (degree) { case 90: rotate90(colors); break; case 180: rotate180(colors); break; case 270: rotate270(colors); 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 rotate90(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[j][SIZE - 1 - i] = colors[i][j]; } } printField(rotatedColors); } public static void rotate180(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[SIZE - 1 - i][SIZE - 1 - j] = colors[i][j]; } } printField(rotatedColors); } public static void rotate270(int[][] colors) { int[][] rotatedColors = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { rotatedColors[SIZE - 1 - j][i] = colors[i][j]; } } printField(rotatedColors); } }