1. Expression Value ----------------------------------------------- 2.5 * 2 * 5 / 10 + 1.5 4.0 85 % 10 + 4 % 10 - 17 % 3 7 (2 + 2 < 3 || 2 * 5 / 3 == 3) == false false 2 + 3 + "." + (3 + 4) + 2 * 3 "5.76" 482 / 10 / 5 / 2.0 * 2 + 14 / 5 11.0 2. Parameter Mystery. The program produces the following output. foo wants buzz to sue. bill wants sue to buzz. bill wants sue to hope. hope wants bill to sue. 3. Method Call Output Produced --------------------------------------- ifElseMystery(5, 2); 12 3 ifElseMystery(8, 3); 5 24 ifElseMystery(6, 2); 3 3 ifElseMystery(2, 8); 11 4 ifElseMystery(6, 7); 5 23 ifElseMystery(4, 7); 3 3 4. Method Call Output Produced --------------------------------------- mystery(8); 1 8 mystery(32); 2 5 mystery(184); 3 13 mystery(8239); 4 22 5. next == 0 prev == 0 next == prev +---------------------+---------------------+---------------------+ Point A | sometimes | always | sometimes | +---------------------+---------------------+---------------------+ Point B | never | sometimes | sometimes | +---------------------+---------------------+---------------------+ Point C | never | never | always | +---------------------+---------------------+---------------------+ Point D | sometimes | never | sometimes | +---------------------+---------------------+---------------------+ Point E | always | sometimes | sometimes | +---------------------+---------------------+---------------------+ 6. Programming. Two possible solutions appear below: public static double tallyVotes(Scanner input) { System.out.print("vote? "); String vote = input.next(); double result = 0; int total = 0; while (!vote.equals("q")) { if (vote.equals("y")) { result++; } total++; System.out.print("vote? "); vote = input.next(); } result = result / total * 100; System.out.println("total votes = " + total); System.out.println("result = " + result + "%"); return result; } public static double tallyVotes(Scanner input) { String vote = ""; int yes = 0; int no = 0; while (!vote.equals("q")) { System.out.print("vote? "); vote = input.next(); if (vote.equals("y")) { yes++; } else if (vote.equals("n")) { no++; } } int total = yes + no; double result = 100.0 * yes / total; System.out.println("total votes = " + total); System.out.println("result = " + result + "%"); return result; } 7. Programming. One possible solution appears below: public static void simulateTeenagers(int n, Random r) { int age = r.nextInt(7) + 13; int sum = age; int min = age; System.out.print("ages: " + age); for (int i = 1; i <= n - 1; i++) { age = r.nextInt(7) + 13; System.out.print(", " + age); sum = sum + age; if (age < min) { min = age; } } System.out.println(); double average = (double) sum / n; System.out.println("average = " + average); System.out.println("minimum = " + min); } 8. One possible solution appears below. public static int digitsInARow(int n) { int max = 1; int count = 1; while (n > 0) { int next = n % 10; n = n / 10; if (n % 10 == next) { count++; } else { count = 1; } if (count > max) { max = count; } } return max; }