
import java.util.Scanner;

/* Write a program that gets an integer from the command line
   and creates an array of length equal to the first value passed
	in on the command line, and populates it with the second 
	value passed in on the command line.

	Include a method named printArray that takes an array of integers
	as an argument and prints the elements in the array to the screen.
 */

class L20 {
	public static void main(String[] args) {

		if (args.length != 2) {
			System.out.println("usage: L20 size value");
			return;
		}	

		int len = Integer.parseInt(args[0]);
		int value = Integer.parseInt(args[1]);

		int[] arr = new int[len];
	
		for(int i = 0; i < len; i++) {
			arr[i] = value;
		}

		printArray(arr);

		int[] newArr = new int[len];
	
		copyArray(arr, newArr);

		printArray(newArr);

		// find the minimum value in an array

		int[] values = {6, 3, 12, 9, 5};

		int smallest = values[0];
		for(int i = 1; i < values.length; i++) {
			if(values[i] < smallest) {
				smallest = values[i];
			}
		}

		System.out.println("smallest: " + smallest);

		int[][] matrix = {{8,3,1},{4,9,5},{6,1,8}};
		int[] minimums = new int[3];

		for(int i = 0; i < matrix.length; i++) {
			smallest = matrix[i][0];
			for(int j = 1; j < matrix[i].length; j++) {
				if(matrix[i][j] < smallest) {
					smallest = matrix[i][j];
				}
			}
			minimums[i] = smallest;
		}

		printArray(minimums);

	} // end of main method

	static void printArray(int[] arr1) {

		for(int i = 0; i < arr1.length; i++) {
			System.out.print(arr1[i] + " ");
		}	
		System.out.println();

		return;
	}

	/* Create a method named copyArray
		that takes two integer array as arguments and
		copies the contents of the first array into the second.
	*/

	static void copyArray(int[] arr1, int[] arr2) {
		int len = arr1.length;

		for(int i = 0; i < len; i++) {
			arr2[i] = arr1[i];
		}
	}
		

		

} // end of class
