
public class ArrayExample {

	public static void main(String[] args) {
		// one-dimensional array
		// define an array of string values
		String[] names = new String[5];

		// assign values to array
		names[0] = "John";
		names[1] = "David";
		names[2] = "Alex";
		names[3] = "Michael";
		names[4] = "George";

		// check the size of array
		System.out.println("There are " + names.length + " values in names.");

		// loop and display values
		for (String name : names) {
			System.out.println(name);
		}

		// multi-dimensional array
		int[][] matrix = new int[3][2];

		// nested loop to assign values
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 2; j++) {
				matrix[i][j] = (int) (Math.random() * 100) + 1;
			}
		}

		// use another nested loop to display the values
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 2; j++) {
				System.out.print(matrix[i][j] + " ");
			}
			System.out.println();
		}

		String message = "Hello World!";
		System.out.println("There are " + message.length() + " characters in message.");

		// read args and display the values
		for (String argument : args) {
			System.out.println(argument);
		}

		int[] values; // declaration
		values = new int[10]; // instantiation
		values[0] = 1; // assignment

		int[] ages = { 1, 2, 3, 4, 5 }; // declaration, instantiation, assignment
	}

}
