import java.util.Scanner;

class Mar12 {

	public static void main(String[] args) {

		Scanner kb = new Scanner(System.in);

		int[] arr1 = new int[5];

		System.out.print("Enter 5 integers: ");

		for(int i = 0; i < 5; i++) {
			arr1[i] = kb.nextInt();
		}

		int max = arr1[0];

		for(int i = 1; i < 5; i++) {
			if (arr1[i] > max) {
				max = arr1[i];
			}
		}
		System.out.printf("max: %d\n", max);

		// do-while loops

		System.out.print("Enter upper bound: ");
		int upperBound = kb.nextInt();

		// a while-loop can possibly execute 0 times

		int i = 0;
		while(i < upperBound) {
			System.out.printf("hello %d\n", i);
			i++;
		}

		// if we need the body of the loop to execute
		// at least once - use do-while loop.

		i = 0;
		do {
			System.out.printf("hello %d\n", i);
			i++;
		} while (i < upperBound);


		char option = 'a';
		do {
			printMenu();
			System.out.print("Enter choice: ");
			option = kb.next().charAt(0);

			// do option

		} while(option != 'e');	

		// for-each loops

		for(int element : arr1) {
			System.out.printf("%d ", element);
		}
		System.out.println();

		max = arr1[0];
		for(int elm: arr1) {
			max = (elm > max) ? elm : max;
		}
		System.out.printf("max: %d\n", max);

		// 2D arrays

		int[][] matrix = new int[4][5];
		
		// set first element of matrix to arr1

		matrix[0] = arr1;
		matrix[1] = arr1;
		matrix[2] = arr1;
		matrix[3] = arr1;

		System.out.printf("length of matrix: %d\n", matrix.length);
		
		for(int[] arr : matrix) {
			printArray(arr);
		}

	}

	static void printMenu() {
		System.out.println("a. Add record");
		System.out.println("e: exit");
	}

	static void printArray(int[] arr) {
		for(int elm: arr) {
			System.out.printf("%d ", elm);
		}
		System.out.println();
	}

}
