class R62 { public static void main(String[] args) { { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 0; i < 10; i++) { total = total + a[i]; } System.out.println( "(a) " + total ); } { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 0; i < 10; i = i + 2) { total = total + a[i]; } System.out.println( "(b) " + total ); } { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 1; i < 10; i = i + 2) { total = total + a[i]; } System.out.println( "(c) " + total ); } try{ { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 2; i <= 10; i++) { total = total + a[i]; } System.out.println( "(d) " + total ); } } catch (Exception e) { System.out.println( "(d) throws a java.lang.ArrayIndexOutOfBoundsException." ); } /***** { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 0; i < 10; i = 2 * i) { total = total + a[i]; } // this is an infinite loop System.out.println( "(e) " + total ); } *****/ try { { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 0; i < 10; i--) { total = total + a[i]; } System.out.println( "(f) " + total ); } } catch (Exception e) { System.out.println( "(f) throws an Exception in thread \"main\" java.lang.ArrayIndexOutOfBoundsException: -1" ); } try { { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 0; i < 10; i = i +-2) { total = total + a[i]; } System.out.println( "(g) " + total ); } } catch (Exception e) { System.out.println( "(g) throws an Exception in thread \"main\" java.lang.ArrayIndexOutOfBoundsException: -2" ); } { int[] a = {1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; int total = 0; for (int i = 0; i < 10; i++) { total = a[i] - total; } System.out.println( "(h) " + total ); } } }