import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;

public class Main {

    public static void main(String[] args) {
        int[] arr = new int[100];
        int min = -99;
        int max = 99;
        Random random = new Random();
        for (int i = 0; i < arr.length; ++i) {
            arr[i] = random.nextInt(max - min + 1) + min;
        }
        System.out.print("Array: ");
        System.out.println(Arrays.toString(arr));

        double[] reciprocal = CreateReciprocalFraction(arr);

        System.out.print("Reciprocal: ");
        System.out.println(Arrays.toString(reciprocal));

        int[] allowed = { -5, 0, -16, 10, 42, -32};
        int count = 0;
        for (int num : arr) {
            for (int allow : allowed) {
                if (num == allow) {
                    count++;
                    break;
                }
            }
        }
        System.out.println("Allowed counter: " + count);

        int negativeCounter = 0;
        for (int n : allowed) {
            if (n < 0) negativeCounter++;
        }

        int[] negaArr = new int[negativeCounter];
        negativeCounter = 0;
        for (int n : allowed) {
            if (n < 0) negaArr[negativeCounter++] = n * 4;
        }
        System.out.print("Negative by 4: ");
        System.out.println(Arrays.toString(negaArr));

        for (int i = 0; i < negaArr.length; ++i) {
            int minIndex = i;
            for (int j = i + 1; j < negaArr.length; ++j) {
                if (negaArr[j] < negaArr[minIndex]) minIndex = j;
            }
            if (i != minIndex) {
                int temp = negaArr[i];
                negaArr[i] = negaArr[minIndex];
                negaArr[minIndex] = temp;
            }
        }
        System.out.print("Negative by 4 sorted: ");
        System.out.println(Arrays.toString(negaArr));



        // 3

        int[][] matrix = new int[4][4];
        for (int i = 0; i < arr.length; ++i) {
        }

        for (int i = 0; i < matrix.length; ++i) {
            for (int j = 0; j < matrix[i].length; ++j) {
                matrix[i][j] = random.nextInt(max - min + 1) + min;
            }
        }
        System.out.println();
        for (int[] row : matrix) {
            System.out.println(Arrays.toString(row));
        }
        System.out.println();
        int[] vec = new int[matrix[0].length];
        for (int j = 0; j < matrix[0].length; ++j) {
            int maxEl = matrix[0][j];
            for (int i = 0; i < matrix.length; ++i) {
                if (matrix[i][j] > maxEl) maxEl = matrix[i][j];
            }
            vec[j] = maxEl;
        }
        System.out.println(Arrays.toString(vec));



        // 4

        int maxEl = matrix[0][0];
        int minEl = matrix[0][0];
        for (int i = 0; i < matrix.length; ++i) {
            if (matrix[i][i] > maxEl) maxEl = matrix[i][i];
            if (matrix[i][i] < minEl) minEl = matrix[i][i];
        }

        System.out.println("Min * Max of main diagonal: " + minEl * maxEl);

        for (int i = 0; i < matrix.length; ++i) {
            System.out.print(minEl * maxEl);
        }
        System.out.println();
    }

    public static double[] CreateReciprocalFraction(int[] arr) {
        double[] result = new double[arr.length];
        for (int i = 0; i < arr.length; ++i) {
            result[i] = 1.0 / arr[i];
        }
        return result;
    }
}
