/* ITI 1121/1521. Introduction to Computer Science II * Assignment/Devoir 3 * * */ public class A5Q1 { public static void main( String[] args ) { StudentInfo.display(); LinkedList l; l = new LinkedList(); for ( int i=0; i<10; i++ ) { l.add( new Integer( i ) ); // adding elements to the list } System.out.println( "l = " + l ); for ( int start=0; start <= l.size(); start++ ) { System.out.println( "start = " + start ); System.out.print( "< " ); Iterator i; i = l.iterator( start ); // creates an iterator starting // at the specified position while ( i.hasNext() ) { System.out.print( i.next() + " " ); } System.out.println( ">" ); } try { Iterator i; i = l.iterator( l.size()+1 ); // starting position out of range } catch ( IndexOutOfBoundsException e ) { System.out.println( "** Caught IndexOutOfBoundsException **" ); } System.out.println(); } } // > java A5Q1 // // ************************************************************ // * * // * * // * * // * * // ************************************************************ // // l = [0,1,2,3,4,5,6,7,8,9] // start = 0 // < 0 1 2 3 4 5 6 7 8 9 > // start = 1 // < 1 2 3 4 5 6 7 8 9 > // start = 2 // < 2 3 4 5 6 7 8 9 > // start = 3 // < 3 4 5 6 7 8 9 > // start = 4 // < 4 5 6 7 8 9 > // start = 5 // < 5 6 7 8 9 > // start = 6 // < 6 7 8 9 > // start = 7 // < 7 8 9 > // start = 8 // < 8 9 > // start = 9 // < 9 > // start = 10 // < > // ** Caught IndexOutOfBoundsException **