
class L34 {

	public static void main(String[] args) {

		int[] arr1 = new int[10];

		// print the contents of arr1 using the print method	
		
		print(arr1);

		// print whether or not 0 exists in arr1 using the exists method
		System.out.println("0 exists in arr1: " + exists(arr1, 0));
		System.out.println("1 exists in arr1: " + exists(arr1, 1));

		/* set all of the elements in arr1 to 3 using setArray*/	
		setArray(arr1, 3);
		print(arr1);

		/* double the values of the elements in arr1 using the doubles method */
		doubles(arr1);
		print(arr1);

		/* create an array that contains the values 2,4,4,6, create an array
			that contains the values 2,3,4, and create an array that contains
			the values 4,6. */

		int[] arr2 = {2,4,4,6};
		int[] arr3 = {2,3,4};
		int[] arr4 = {2,4};	

		System.out.println("exists: " + exists(arr2,arr3));
		System.out.println("exists: " + exists(arr2,arr4));
	
	}

	/* write a method named print that prints the contents of
		an array of integers on a single line. */


	static void print(int[] arr) {
		for(int elm : arr) {
			System.out.print(elm + " ");
		}
		System.out.println();
	}

	/* write a method named exists that takes an array of integers and a integer
		as arguments and returns true if the second parameter exists in the first.
		Otherwise it returns false. */

	static boolean exists(int[] arr, int key) {
		for(int elm : arr) {
			if (elm == key) {
				return true;
			}
		}
		return false;	
	}


	/* write a method named setArray that takes an array of integers and an integer
		as arguments and sets all of the elements in the array equal to the value of
		the second parameter. */

	static void setArray(int[] arr, int val) {
		for(int i = 0; i < arr.length; i++) {
			arr[i] = val;
		}
	} 

	/* write a method named doubles that takes an array of integers as an argument
		and doubles the value of each element in the array. */

	static void doubles(int[] arr) {
		for(int i = 0; i < arr.length; i++) {
			arr[i] = arr[i] * 2;
		}
	}

	/* write a method named exists that takes 2 arrays of integers as arguements.
		The method returns true if each of the elements in the second array exist
		in the first array.  Otherwise it returns false. */

	static boolean exists(int[] arr, int[] keys) {
		for(int i = 0; i < keys.length; i++) {
			boolean found = false;
			int key = keys[i];
			for(int j = 0; j < arr.length; j++) {
				if (arr[i] == key) {
					found = true;
					break;	
				}
			}
			if(found == false) {
				return false;
			}		
		}		
		return true;
	}





} // End of class
