import java.util.Scanner;

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

		Scanner kb = new Scanner(System.in);

		int i = 5;		// initialize counting var
		while(i > 0) {		// testing counting var
			System.out.print(i + " ");
			i--;		// incrementing counting var
		}
		System.out.println();


		i = 0;		// initialize counting var
		while(i < 5) {		// testing counting var
			System.out.print(i + " ");
			i++;		// incrementing counting var
		}
		System.out.println();
		

		// for-loop:  equivalent code to above

		for(int j = 0; j < 5; j++) {
			System.out.print(j + " ");
		}
		System.out.println();

		/*
		for(;;) {
			System.out.println("stuck in a loop");
		}
		*/

		int j = 0;
		for(;j < 5;) {
			System.out.print(j + " ");
			j++;
		}
		System.out.println();
		
		// user for-loop to get data an populate array

		String[] names = new String[3];

		System.out.println("Please enter 3 names");

		for(int k = 0; k < 3; k++) {
			names[k] = kb.next();
		}	

		for(int k = 0; k < names.length; k++) {
			System.out.println(names[k]);
		}	

		int[] numbers = {1,2,3,2,1};

		int result = count(numbers, 3);
		System.out.println("result: " + result);

		result = count(numbers, 2);
		System.out.println("result: " + result);

		boolean found = isPresent(numbers, 3);
		System.out.println("found: " + found);
		
		found = isPresent(numbers, 7);
		System.out.println("found: " + found);
	
	}

	//write a method named count that takes an array of integers
	// and an integer as argments and returns the number of 
	// times the second argument is found in the first argument.

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

	/*
	write a method named isPresent that takes an array of 
	integers and an integer as arguments 
	and returns true if the second argument is found in 
	the first argument, otherwise returns false
	*/

	static boolean isPresent(int[] arr, int k) {
		for(int i = 0; i < arr.length; i++) {
			if(arr[i] == k) {
				return true;
			}
		}
		return false;
	}




}
