1. 6 * 2 + 8 / 2 * 3 24 3 * 6 * 2.0 / 5 + 3 / 4 7.2 25 % (9 - 5) - 33 % 9 % 4 -1 5 + 2 * 3 + "6" + 15 + 2 + "(1 + 1)" "116152(1 + 1)" 1000 / 5 / (30 / 7) / 8.0 + 10 / 4.0 8.75 2. apple like apple and smoothies apple like pizza and apple skiers like smoothies and pizza smoothies like smoothies and snow pizza like apple-pizza and pizza 3. mystery(1) 1 mystery(6) 2 3 mystery(21) 3 7 mystery(24) 2 2 2 3 mystery(120) 2 2 2 3 5 4. x <= y y > z x == 11 +-----------+-----------+-----------+ Point A | always | sometimes | never | +-----------+-----------+-----------+ Point B | sometimes | never | sometimes | +-----------+-----------+-----------+ Point C | always | never | never | +-----------+-----------+-----------+ Point D | sometimes | sometimes | sometimes | +-----------+-----------+-----------+ Point E | sometimes | always | sometimes | +-----------+-----------+-----------+ 5. Three solutions are shown. public static int rockPaperScissors(int p1, int p2) { if (p1 == 0 && p2 == 1 || p1 == 1 && p2 == 2 || p1 == 2 && p2 == 0) { return 1; } else if (p1 == 0 && p2 == 2 || p1 == 1 && p2 == 0 || p2 == 2 && p2 == 1) { return 2; } else { return 0; // tie } } public static int rockPaperScissors(int p1, int p2) { if (p1 == p2) { return 0; // tie } else if (p1 == 0 && p2 == 1 || p1 == 1 && p2 == 2 || p1 == 2 && p2 == 0) { return 1; } else { return 2; } } public static int rockPaperScissors(int p1, int p2) { } else if ((p1 + 1) % 3 == p2) { return 1; } else if ((p2 + 1) % 3 == p1) { return 2; } else { return 0; // tie } } 6. Two solutions are shown. public static int longestWord(String s) { int currentLength = 0; int longest = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == ' ') { currentLength = 0; } else { currentLength++; longest = Math.max(longest, currentLength); } } return longest; } public static int longestWord2(String s) { int currentLength = 0; int longest = 0; int start = 0; while (start < s.length()) { while (start < s.length() && s.charAt(start) == ' ') { start++; } int end = start; while (end < s.length() && s.charAt(end) != ' ') { end++; } if (end - start > longest) { longest = end - start; } start = end; } return longest; } 7. public static int getOddInteger(Scanner console) { System.out.print("Type an odd integer: "); int n = 0; while (n % 2 == 0) { if (console.hasNextInt()) { n = console.nextInt(); } else { console.next(); // discard token } if (n % 2 == 0) { System.out.println("Invalid input, try again."); System.out.print("Type an odd integer: "); } } return n; }