import java.util.Scanner;

class Dec1 {

	public static void main(String[] args) {

		// create a scanner that can read from the keyboard

		Scanner kb = new Scanner(System.in);	
	
		// read an integer from the keyboard, print "yellow" if 
		// the integer is odd, print "green" otherwise

		System.out.println("Enter integer");
		int input = kb.nextInt();
		if (input % 2 == 1) {
			System.out.println("yellow");
		}
		else {
			System.out.println("green");
		}

		// do the same as above using the ?: operator 

		System.out.println((input % 2 == 1) ? "yellow" : "green");	
		// use a switch statement to print "yellow" if the input
		// is 1, otherwise print "green"

		switch(input) {
			case 1: 
				System.out.println("yellow");
				break;
			default:
				System.out.println("green");
		}	
	
		// read char from kb. use switch to print "yellow" char
		// is the letter a and print "green" if it is the letter b.

		System.out.println("Enter character");
		char cinput = kb.next().charAt(0);

		switch(cinput) {
			case 'a':
				System.out.println("yellow");
				break;
			case 'b':
				System.out.println("green");

		}
		
		// print integers between 1 and 10 (inclusively) using 
		// a while loop

		int count = 1;
		while(count <= 10) {
			System.out.printf("%d ", count);
			count++;
		}
		System.out.println();

		// same with do-while loop

		count = 1;
		do {
			System.out.printf("%d ", count);
			count++;
		} while(count <= 10);
		System.out.println();
					
		// same with for-loop

		for(int i = 1; i <= 10; i++) {
			System.out.printf("%d ", i);
		}
		System.out.println();

		// print 10 to 1 using a for-loop

		for(int i = 10; i >= 1; i--){
			System.out.printf("%d ", i);
		}
		System.out.println();

		// read int from kb, allocate array of ints whose
		// length is equal to value read from kb

		System.out.println("Enter array length");
		int len = kb.nextInt();

		int[] arr = new int[len];

		// print length of arr to screen

		System.out.println("len: " + arr.length);

		// set all elements in arr to the value 9

		for(int i = 0; i < arr.length; i++) {
			arr[i] = 9;
		}

		// print elements in arr to screen 
		for(int i = 0; i < arr.length; i++) {
			System.out.printf("%d ", arr[i]);
		}
		System.out.println();

		// ask user for 2 integers.  allocate 2D array
		// whose dimensions are equal to values read from kb

		System.out.println("Enter 2 integers");
		int numRows = kb.nextInt();
		int numCols = kb.nextInt();

		int[][] matrix = new int[numRows][numCols];

		// put 1's on the diagonal

		for(int i = 0; i < numRows; i++) {
			for(int j = 0; j < numCols; j++) {
				if (i == j) {
					matrix[i][j] = 1;
				}
			}
		}	
	
		// print contents of matrix to screen 

		for(int i = 0; i < numRows; i++) {
			for(int j = 0; j < numCols; j++) {
				System.out.print(matrix[i][j] + " ");
			}
			System.out.println();
		}	


	
	}
}
