Lecture Notes on 22 Jul 2013 public class TestArray { public static int[] reverseArray1 (int[] a) { int[] b = new int [a.length]; for (int i = 0; i < a.length ; i++) { b[i] = a[a.length - 1 - i]; } return b; } public static int sumArray (int[] a) { int sum = 0; for (int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } public static int maxArray (int[] a) { int max = a[0]; for (int i = 1; i < a.length; i++) { if (a[i] > max) max = a[i]; } return max; } public static int max2Array (int[] a) { int max1, max2; if (a[0] > a[1]) { max1 = a[0]; max2 = a[1]; } else { max1 = a[1]; max2 = a[0]; } for (int i = 2; i < a.length; i++) { if (a[i] > max1) { max2 = max1; max1 = a[i]; } else if (a[i] > max2) { max2 = a[i]; } } return max2; } public static void reverseArray2 (int[] a) { int tmp = 0; for (int i = 0; i < a.length; i++) { tmp = a[i]; a[i] = a[a.length - 1 - i]; a[a.length - 1 - i] = tmp; } } public static boolean isPalindromic (int[] a) { for (int i = 0; i < a.length / 2; i++) { if (a[i] != a[a.length - 1 - i]) return false; } return true; } public static void main (String[] args) { int[] a = {8, 3, 6, 1, 5}; for (int i = 0; i < a.length; i++) { System.out.println (a[i]); } } }