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));


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

        for (int i = 0; i < matrix.length; i++) { // Iterates through rows
            for (int j = 0; j < matrix[i].length; j++) { // Iterates through columns of the current row
                matrix[i][j] = random.nextInt(max - min + 1) + min;
            }
        }
        System.out.println();
        for (int[] row : matrix) { // Iterates through rows
            // System.out.print(matrix[i][j] + " ");
            System.out.println(Arrays.toString(row));
        }
        System.out.println(); // Move to the next line after each row
        int[] vec = new int[matrix[0].length];
        for (int j = 0; j < matrix[0].length; j++) { 
            int max_el = matrix[0][j];
            for (int i = 0; i < matrix.length; i++) { // Iterates through rows
                if (matrix[i][j] > max_el) max_el = matrix[i][j];
            }
            vec[j] = max_el;
        }
        System.out.println(Arrays.toString(vec));
        // if (args.length > 0) {
        //     switch (Integer.parseInt(args[0])) {
        //         case 1: first(args);  break;
        //         case 2: second(args); break;
        //         case 3: third(args);  break;
        //     }
        // }
    }

    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;
    }

    public static void first(String[] args) {
    }

    public static void third(String[] args) {
        if (args.length == 2) {
            double x = Double.parseDouble(args[1]);
            double y, f;
            if (x <= 1) {
                y = Math.pow(x, 5) + Math.atan(8 * x);
                f = Math.exp(Math.tan(x + 1));
            }
            else if (x > 3) {
                y = 1 / Math.tan(2 * x + 1);
                f = Math.pow(Math.pow(x, 2), 1.0/5.0);
            }
            else {
                y = 5 * x - (1 + Math.pow(3, x));
                f = Math.pow(x, 4) - Math.tan(4 * x);
            }
            System.out.printf("Y: %f\n", y);
            System.out.printf("F: %f\n", f);

        } else {
            System.out.println("No arguments");

        }
    }
}
