/
PolinaMakhrova
/
ARR
Обзор
Документация
Войти
/
PolinaMakhrova
/
ARR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Main.java
125 строк
4 KB
PolinaMakhrova
upload files
23 фев 2025, 00:27
23 фев 2025, 00:27
90a538a
Код
Авторство
О чём код?
import java.util.Random; import java.util.Scanner; public class Main { public static final int SIZE = 3; 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); } } for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.format("%4d", colors[i][j]); } System.out.println(); } Turn90(colors); } public static void Turn90(int[][] colors) { int[][] rotatedColors90 = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { int n = SIZE - 1; for (int j = 0; j < SIZE; j++) { int temp = colors[n][i]; rotatedColors90[i][j] = temp; n = n - 1; } } int[][] rotatedColors90again = new int[SIZE][SIZE]; for (int i = 0; i < SIZE; i++) { int n = SIZE - 1; for (int j = 0; j < SIZE; j++) { int temp = rotatedColors90[n][i]; rotatedColors90again[i][j] = temp; n = n - 1; } } int[][] rotatedColors270 = new int[SIZE][SIZE]; int n = SIZE - 1; for (int i = 0; i < SIZE; i++) { int p = 0; for (int j = 0; j < SIZE; j++) { int temp = colors[p][n]; rotatedColors270[i][j] = temp; p = p + 1; } n = n - 1; } while (true) { Scanner scanner = new Scanner(System.in); System.out.println("Ведите градус повората 1,если-90 градусов,2-если-180, 3-если 270,4-выход"); String x = scanner.nextLine(); if ("4".equals(x)) { break; } else if ("1".equals(x)) { //int forPrint [][] =rotatedColors90 -почему я так // присвоить не могу?чтобы потом делать обработку для печати ниже для массива porPrint for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.format("%4d", rotatedColors90[i][j]); } System.out.println(); } } else if ("2".equals(x)) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.format("%4d", rotatedColors90again[i][j]); } System.out.println(); } } if ("3".equals(x)) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { System.out.format("%4d", rotatedColors270[i][j]); } System.out.println(); } } } } } //public static void Turn180 ( int[][] colors){ // int[][] rotatedColors180 = new int[SIZE][SIZE]; //int k = SIZE - 1; //for (int i = 0; i < SIZE; i++) { //int n = SIZE - 1; //for (int j = 0; j < SIZE; j++) { //int temp = colors[k][n]; // rotatedColors180[i][j] = temp; // n = n - 1; // } // k = k - 1; // } //public static void Turn ( int[][] colors){ //int[][] rotatedColors360 = new int[SIZE][SIZE]; // for (int i = 0; i < SIZE; i++) { // int n = SIZE - 1; // for (int j = 0; j < SIZE; j++) { // int temp = colors[i][n]; // rotatedColors360[i][j] = temp; // n = n - 1; // } //}