1. Expression Value -------------------------------------------------------- 4 * (2 + 4) - 3 * 5.25 8.25 85 % 5 + 4 % 3 - 20 % 6 -1 12 / 5 + 2 * 5.0 + 2 / 4 12.0 3 + 3 + "." + (3 + 3) + 3 * 3 "6.69" (11 > 7 + 6 || 3 * 2 <= 39 % 10) == true true 2. Parameter Mystery. The program produces the following output. oooh watch me naenae, watch me leg leg watch me oooh, watch me bopbop now watch me whip, watch me naenae whip watch me naenae, watch me whip 3. Method Call Output Produced --------------------------------------- ifElseMystery(2, 8); 7 8 ifElseMystery(6, 10); 10 5 ifElseMystery(2, 7); 7 2 ifElseMystery(12, 9); 15 5 ifElseMystery(7, 7); 10 3 ifElseMystery(4, 5); 8 1 4. Method Call Output Produced --------------------------------------- whileMystery(1); 1 whileMystery(3); 2, 2 whileMystery(5); 2, 3, 5, 5 whileMystery(7); 2, 3, 5, 8, 13, 13 5. next < 0 next == 0 x > 0 +---------------------+---------------------+---------------------+ Point A | sometimes | sometimes | never | +---------------------+---------------------+---------------------+ Point B | sometimes | never | sometimes | +---------------------+---------------------+---------------------+ Point C | always | never | always | +---------------------+---------------------+---------------------+ Point D | sometimes | sometimes | sometimes | +---------------------+---------------------+---------------------+ Point E | never | always | sometimes | +---------------------+---------------------+---------------------+ 6. Programming. One possible solution appears below: public static void war(Scanner console, int cards) { int total1 = cards; int total2 = cards; while (total1 > 0 && total2 > 0) { System.out.print("[" + total1 + "/" + total2 + " card split] Top cards? "); int card1 = console.nextInt(); int card2 = console.nextInt(); if (card1 > card2) { total1++; total2--; } else if (card2 > card1) { total2++; total1--; } } if (total1 > 0) { System.out.println("Player 1 wins!"); } else { System.out.println("Player 2 wins!"); } } 7. Programming. One possible solution appears below: public static void findValetines(Random r, int n) { System.out.println("Will you be my valentine?") int yeses = 0; int firstResponse = rand.nextInt(5); if (response == 0) { System.out.print("yes"); yeses++; } else { System.out.print("no"); } for (int i = 1; i <= n - 1; i++) { int response = rand.nextInt(5); if (response == 0) { System.out.print(", yes"); yeses++; } else { System.out.print(", no"); } } System.out.println(); double percent = (double) yeses / n * 100; System.out.println(yeses + " yeses, " + percent + "%"); } 8. Two possible solutions appear below. public static int indexOf(String s1, String s2) { for (int i = 0; i <= s1.length() - s2.length(); i++) { boolean matches = true; for (int j = 0; j < s2.length(); j++) { if (s1.charAt(i + j) != s2.charAt(j)) { matches = false; } } if (matches) { return i; } } return -1; } public static int indexOf(String s1, String s2) { for (int i = 0; i <= s1.length() - s2.length(); i++) { String substring = ""; for (int j = 0; j < s2.length(); j++) { substring += s1.charAt(i + j); } if (substring.equals(s2)) { return i; } } return -1; }