1. 2 3 4 2. public class Question2 { public static double findNext(double x, double[] a) { double y = Double.POSITIVE_INFINITY; for (int i = 0; i < a.length; i++) { if (a[i] > x && a[i] < y) y = a[i]; } return y; } public static void main(String[] args) { double x = Double.parseDouble(args[0]); double[] a = new double[args.length-1]; for (int i = 1; i < args.length; i++) { a[i-1] = Double.parseDouble(args[i]); } System.out.println(findNext(x, a)); } } 3. public class Card { private double saldo; private long validTo; private static long TICKET_VALIDITY = 5400000; private static double TICKET_PRICE = 22; private static double SALDO_LIMIT = -20; public Card(double saldo) { this.saldo = saldo; this.validTo = System.currentTimeMillis()-1; } public void load(double credit) { saldo += credit; } public double getSaldo() { return saldo; } public long validTo() { return validTo; } public Status stamp() { long time = System.currentTimeMillis(); if (time < validTo) return Status.BYTE; if (saldo - TICKET_PRICE < SALDO_LIMIT) return Status.FAIL; validTo = time + TICKET_VALIDITY; saldo -= TICKET_PRICE; return Status.OK; } } 4. public static int pow(int x, int n) { int p = 1; while (n > 0) { if (n % 2 != 0) { p = p * x; } x = x * x; n = n / 2; } return p; } 5.  public static List getCheapestFlight(String src, String dst) throws FileNotFoundException { List flights = new ArrayList(); int minPrice = Integer.MAX_VALUE; Scanner scanner = new Scanner("flights.txt"); while (scanner.hasNext()) { String src1 = scanner.next(); String dst1 = scanner.next(); String flight = scanner.next(); int price = scanner.nextInt(); if (src.equals(src1) && dst.equals(dst1)) { if (minPrice > price) { minPrice = price; flights.clear(); } if (minPrice == price) { flights.add(flight); } } } return flights; }