Array Programs

5. Program

How to read elementss of array element in the reverse order ?

class L { public static void main(String[] args) { int[] a = {2, 34, 4, 16, 77, 1, 8}; for(int i = a.length - 1 ; i >= 0 ; i--) { System.out.print( a[i] + ", "); } } }

6. Program

how to print odd index element from an array ?

class M { public static void main(String[] args) { int[] a = {2, 34, 4, 16, 77, 1, 8}; for(int i = 1 ; i < a.length ; i += 2) { System.out.print( a[i] + ", "); } } }

7. Program

How to read only even indexed elements from an array?

class N { public static void main(String args[]) { int[] a = {10, 22, 33, 77, 10, 30, 11, 3, 5}; for(int i = 0; i < a.length ; i = i + 2) { System.out.println(a[i]); } } }

Page....