import java.util.Arrays;

class Nov20 {

	public static void main(String[] args) {

		
		// create a 3x5 2D array of integer

		int[][] arr = new int[3][5];
		
		// print the 2D array so that each row is on
		// a separate line and the values in each row
		// are separated by spaces

		System.out.println("2D array");
		for(int i = 0; i < arr.length; i++) { // counting rows
			for(int j = 0; j < arr[i].length; j++) { // counting cols
				System.out.printf("%d ", arr[i][j]);
			}
			System.out.println();
		}
		System.out.println();

		// create a 3D array of integers 
		// a 3D array is an array of 2D arrays

		int[][][] cube = new int[5][5][5];

		// make it so that the 2D arrays hold different values

		for(int i = 0; i < cube.length; i++) { 
			for(int j = 0; j < cube[i].length; j++) { 
				for(int k = 0; k < cube[i][j].length; k++) {
					cube[i][j][k] = i + 1;
				}
			}
		}

		System.out.println("3D array");
		for(int j = 0; j < 5; j++) { 
			for(int i = 0; i < 5; i++) { 
				for(int k = 0; k < 5; k++) {
					System.out.printf("%d ", cube[i][j][k]);
				}
				System.out.printf("\t");
			}
			System.out.println();
		}
		System.out.println();

		// set random values in arr
		System.out.println("Setting random values in arr");
		for(int i = 0; i < arr.length; i++) {
			for(int j = 0; j < arr[i].length; j++) {
				arr[i][j] = (int) Math.floor(Math.random() * 10);
			}
		} 		

		for(int i = 0; i < arr.length; i++) { // counting rows
			for(int j = 0; j < arr[i].length; j++) { // counting cols
				System.out.printf("%d ", arr[i][j]);
			}
			System.out.println();
		}
		System.out.println();

		// create an array with random integers, then sort them
		// using the first row in arr

		int[] row0 = arr[0];

		System.out.print("Before sort: ");		
		for(int i = 0; i < row0.length; i++) {
			System.out.printf("%d ", row0[i]);
		}	
		System.out.println();

		Arrays.sort(row0);

		System.out.print("After sort: ");
		for(int i = 0; i < row0.length; i++) {
			System.out.printf("%d ", row0[i]);
		}	
		System.out.println();
		System.out.println();		


		// initialize a 2D array with random characters

		char[][] m2 = new char[3][3];

		System.out.println("2D array of random characters");
		for(int i = 0; i < m2.length; i++) { 
			for(int j = 0; j < m2[i].length; j++) {
				m2[i][j] = (char) (int) Math.floor(Math.random() * 26 + 97);	
			}
		}
		
		for(int i = 0; i < m2.length; i++) { 
			for(int j = 0; j < m2[i].length; j++) {
				System.out.printf("%c ", m2[i][j]);	
			}
			System.out.println();
		}
		System.out.println();

	}
}

