

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

		int[] arr1 = {0,1,2,3,2,2};
		System.out.println("index of 0: " + indexOf(arr1,0));
		System.out.println("index of 1: " + indexOf(arr1,1)); 		
		System.out.println("index of 2: " + indexOf(arr1,2)); 		

		System.out.println("count of 2s: " + count(arr1, 2));
	}

	/* Write a method named count that takes an array of integers
		and an integer as arguments and returns the number of
		instances of the integer found in the array.
	*/

	static int count(int[] arr, int x) {
		int count = 0;
		for(int i = 0; i < arr.length; i++) {
			if (arr[i] == x) {
				count++;
			}
		}
		return count;
	}

	/* Write a method named indexOf that takes an array
		of integers and an integer as an argument and 
		returns the array index of the first instance 
		of the integer passed into the method. Return -1
		if the integer is not found.
	*/
			
	static int indexOf(int[] arr, int x) {
		for(int i = 0; i < arr.length; i++) {
			if (x == arr[i]) {
				return i;
			}
		}
		return -1;
	}

}
