import java.lang.String ;

class Pair {
int x, y;

public Pair (int i, int j) { x=i; y=j; }
public void prn () { System.out.println (x + " " + y ); }

}


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

	int[] A;  		// or also int A [] like C, C++
	Pair P[];		// array of Pairs

		//----------- using integer array -----------

		A = new int [10] ; // an array of 10 integers 

		for (int i=0; i<10; i++) A [i] = i ;	 // write to locations in the array

		System.out.println ("let's print the elements of array A");

		for (int i=0; i<10; i++) System.out.println (A[i]);

		//------ another example --------------------

		P = new Pair [10]; // P becomes an array of 10 pairs 
		
		for (int i=0; i<10; i++) P [i] = new Pair (i,i+1); 
			// actual objects are allocated into the array

		System.out.println ("let's print the elements of array P");
		for (int i=0; i<10; i++) P[i].prn ();  // messages sent to respective objects

		//------- knowing the length of array ----------------------
				
		System.out.println ("\nP array has " + P.length + " elements");
		System.out.println ();

		//---------- what happens on array bound violations? ----------
		//

		System.out.println ("let's try to print 12 elements from P");

		for (int i=11; i>=0; i--)  {	

			try  { P [i].prn ();
			       System.out.println("watch this"); }

			catch (Exception e) {
				System.out.println ("\nArrayTest threw " +
					"exception " + "object of class " + 
					e.getClass() + " with message " +
				e.getMessage () + "\n" );
			}

			finally { }
		}
	}
}


