import java.util.Scanner;

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

		int[][] m = {{1}, {2,3}, {4,5,6}};
		printMatrix(m);
		printMatrix2(m);		

		printRow(m,1);

	}

	/* Write a method named printRow that takes
		a 2D array of integers and an integer 
		k, as arguments and prints the kth row 
		of elements in the 2D array 

		e.g. in {{1,2},{3,4}} if k=2, we print {3,4}
	*/

	static void printRow(int[][] m, int k) {
		if(k < 0 || k >= m.length) {
			return;
		}

		for(int x : m[k-1]) {
			System.out.print(x + " ");
		}
		System.out.println();
	}	

	// Write a method named printMatrix that takes a 2D array
	// of integers as an argument and prints the elements
	// of the matrix to the screen,a row on each line, with
	// spaces between the elements.

	static void printMatrix(int[][] matrix) {
		//get each row
		for(int i = 0; i < matrix.length; i++) {
			int[] row = matrix[i];
			// print row
			for(int j = 0; j < row.length; j++) {
				int x = row[j];
				System.out.print(x + " ");	
			}
			System.out.println();
		}
	}

	static void printMatrix2(int[][] m) {
		for (int[] row : m) {
			for(int x : row) {
				System.out.print(x + " ");
			}
			System.out.println();
		}
	}
		

}// end of class
