
public class ArrayExamples {

	/*
	 * Example code
	 */
	public static void main(String[] args) {
		
		// 1D Array.
		int[] arr;
		arr = new int[5];
		for (int x = 0; x < arr.length; x++) {
			arr[x]  = x*x;
		}
		System.out.println ("\n1D Array:");
		// Not valid method
		//print1DintArray (arr);
		for (int x = 0; x < arr.length; x++) {
			System.out.println(arr[x]);
		}
		
		// Hard-coded 1D Array
		int[] arrh = {1,2,3,4,5};
		System.out.println ("\n1D Array hardcoded:");
		for (int x = 0; x < arrh.length; x++) {
			System.out.println(arrh[x]);
		}
				
		// 2D Array
		String[][] arr2;
		arr2 = new String [6][8];
		System.out.println("\n2D Array:");
		for (int x = 0; x < arr2.length; x++) {
			for (int y = 0; y < arr2[x].length; y++) {
				arr2[x][y] = x + "," + y;
				System.out.println(arr2[x][y]);
				// Last item printed will be "5,7"
			}
		}
				
		// Hard-coded 2D Array
		// Makes a 3 x 3 array
		String[][] arrh2 = {{"0,0", "0,1", "0,2"}, {"1,0", "1,1", "1,2"}, {"2,0", "2,1", "2,2"}};
		System.out.println("\n2D Array hardcoded:");
		for (int x = 0; x < arrh2.length; x++){
			for (int y = 0; y < arrh2[x].length; y++) {
				System.out.println(arrh2[x][y]);
			}
		}
		
		// Integer 2D Array
		int[][] intarr2;
		intarr2 = new int [6][8];
		System.out.println("\n2D Array:");
		for (int x = 0; x < intarr2.length; x++) {
			for (int y = 0; y < intarr2[x].length; y++) {
				intarr2[x][y] = x*10+y;
				System.out.println(intarr2[x][y]);
				// Last item printed will be "5,7"
			}
		}
		
		// Integer Hard-coded 2D Array
		int[][] intarrh2 = {{1,2,3,4,5}, {2,4,6,8,10}};
		System.out.println("\nInteger 2D Array hardcoded:");
		for (int x = 0; x < intarrh2.length; x++) {
			for (int y = 0; y < intarrh2[x].length; y++) {
				System.out.println(intarrh2[x][y]);
			}
		}
				
	}

}
