1. Answer: 0 2 4 6 0 2. public class Question2 { public static boolean isProgression(int[] a) { if (a.length <= 2) return true; int diff = a[1]-a[0]; for (int i = 0; i < a.length-1; i++) { if (a[i+1]-a[i] != diff) return false; } return true; } public static void main(String[] args) { int[] a = new int[args.length]; for (int i = 0; i < args.length; i++) { a[i] = Integer.parseInt(args[i]); } System.out.println(isProgression(a)); } } 3. public class Battery { private int power; private List listeners; public Battery(int power) { this.power = power; this.listeners = new ArrayList(); } public void charge(int delta) { power += delta; for (Object o : listeners) { BatteryListener l = (BatteryListener) o; l.updateStatus(power); } } public void addListener(BatteryListener l) { listeners.add(l); } } public class TestBatteryListener implements BatteryListener { public void updateStatus(int power) { System.out.println(power); } } 4. public class Question4 { public static char[] generateCipher() { char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); char[] cypher = new char[26]; for (int i = 0; i < cypher.length; i++) { boolean duplicate; do { cypher[i] = alphabet[(int) (Math.random()*alphabet.length)]; duplicate = false; for (int j = 0; j < i; j++) { if (cypher[i] == cypher[j]) { duplicate = true; break; } } } while (duplicate); } return cypher; } public static void main(String[] args) { System.out.println(generateCipher()); } } 5. public static boolean isEasy(File dictionary, String password) throws FileNotFoundException { Scanner scanner = new Scanner(dictionary); while (scanner.hasNext()) { String word = scanner.next(); if (word.equals(password)) return true; } return false; }