Задачка

mail@pastecode.io avatar
unknown
java
a year ago
919 B
17
Indexable
import java.util.Random;

public class Main {
    public static void main(String[] args) {
        int sizeOfTable = 7;
        int[][] table = new int[sizeOfTable][sizeOfTable];
        Random random = new Random();

        for (int i = 0; i < sizeOfTable; i++) {
            for (int j = 0; j < sizeOfTable; j++) {
                if (i == j || i == sizeOfTable - j - 1)
                    table[i][j] = 0;
                else if ((i < j && j < sizeOfTable - i - 1) || (i > j && j > sizeOfTable - i - 1))
                    table[i][j] = random.nextInt(5) + 1;
                else
                    table[i][j] = -random.nextInt(5) - 1;
            }
        }

        for (int i = 0; i < sizeOfTable; i++) {
            for (int j = 0; j < sizeOfTable; j++) {
                System.out.printf("%4d", table[i][j]);
            }
            System.out.println();
        }
    }
}