IT168 Skill Assessment Test 2 Definitive Study Guide
General Course Overview and Assessment Guidelines
Course Information: IT168 — Structured Problem Solving Using The Computer (Fall 2026 Skill Assessment Test 2 Practice Set).
Core Subject Focus: Heavy emphasis on control structures, including decisions, single and nested loops, sentinel values, input validation, and structured logical thinking.
Test Section Structure and Scoring:
Section A (Multiple Choice): 30 questions (M01 through M30), worth 5 points each (total 150 points).
Section B (Short Answer): 30 multi-part questions (S01 through S30), worth 10 points each (total 300 points).
Section C (Programming Problems): 40 individual programming problems (P01 through P40), worth 50 points each.

Execution, Tracing, and Programming Environment Rules
Timed Practice Protocol:
Complete programming problems in one full hour per problem.
Write code using a plain-text editor or physical paper without relying on Eclipse IDE, autocomplete features, or automated compiler error corrections.
Complete a manual trace and logic verification before compiling code.
Snippet Execution Context:
All code snippets are assumed to execute within
public static void main(String[] args).Standard import
import java.util.Scanner;is assumed to be present.Variables explicitly mentioned as pre-declared are available in scope.
Snippets are completely independent and may contain intentional syntax or runtime errors.
Code Tracing Rules:
Iteration Definition: An iteration is defined as one entry into a loop body, including any entry prematurely interrupted by
breakorcontinuestatements.Condition Evaluation: Loop condition checks must be counted separately from loop body executions.
Output Format: Evaluate exact program-produced text (ignore prompt strings or stack trace messages). Quotes in answer choices delimit string literals and are not output. "then" denotes line breaks. Preserve leading whitespace, literal dots, and blank lines; ignore trailing spaces.
Scope and Syntax Restrictions:
Allowed Java Features: Standard primitive types, arithmetic operators, relational/logical operators (
&&,||,!),if-elsebranching,while,do-while, basicforloops,break,continue,Scannerinput, and basicStringmethods (length(),charAt()).Prohibited Features: Custom methods or classes outside
main, arrays (except the unusedargsparameter), Java Collections Framework, recursion, Java Streams, regular expressions,String.split(),StringBuilder, orString.repeat().
Data and Program Input Assumptions:
All numeric input values are valid integers unless specified otherwise.
Source code file name must match the class name with
.javaextension.Sentinels and rejected values do not count as valid data.
Section A: Multiple Choice Questions and Detailed Traces
M01: Updating a running total
Project:
IT168_SA2_M01| Package:it168.sa2.m01| Class:QuestionM01Code Snippet:
java int x = 1; int total = 0; while (x < 6) { total += x + 1; System.out.println(x + ":" + total); x += 2; } Execution Trace:
Initial:
x = 1,total = 0Iteration 1:
x = 1( is true).total += 2(\n total = 2\n ). Prints1:2.xbecomes3.Iteration 2:
x = 3( is true).total += 4(\n total = 6\n ). Prints3:6.xbecomes5.Iteration 3:
x = 5( is true).total += 6(\n total = 12\n ). Prints5:12.xbecomes7.Termination:
x = 7( is false).Answer: A ("1:2", then "3:6", then "5:12")
M02: A first pass through do-while
Project:
IT168_SA2_M02| Package:it168.sa2.m02| Class:QuestionM02Code Snippet:
java int n = 8; do { System.out.print(n + " "); n -= 2; } while (n < 5); System.out.println("|" + n); Execution Trace:
Iteration 1: Prints
8.nupdated to6. Condition check is false. Loop terminates.After loop: Prints
|6.Total Output:
8 |6Answer: B ("8 |6")
M03: A descending for loop
Project:
IT168_SA2_M03| Package:it168.sa2.m03| Class:QuestionM03Code Snippet:
java for (int value = 11; value >= 2; value -= 3) { System.out.println(value); } Execution Trace:
value = 11(): executes body (1)value = 8(): executes body (2)value = 5(): executes body (3)value = 2(): executes body (4)value = -1( is false): loop ends.Answer: D (4)
M04: A multiplicative update
Project:
IT168_SA2_M04| Package:it168.sa2.m04| Class:QuestionM04Code Snippet:
java int value = 3; int rounds = 0; while (value < 80) { value *= 3; rounds++; } System.out.println(rounds + " " + value); Execution Trace:
Initial:
value = 3,rounds = 0Check (true) -> Iteration 1:
value = 9,rounds = 1Check (true) -> Iteration 2:
value = 27,rounds = 2Check (true) -> Iteration 3:
value = 81,rounds = 3Check (false) -> Loop exits.
Output:
3 81Answer: D ("3 81")
M05: continue in a for loop
Project:
IT168_SA2_M05| Package:it168.sa2.m05| Class:QuestionM05Code Snippet:
java for (int i = 1; i <= 6; i++) { if (i % 3 == 0) { continue; } System.out.print(i + " "); } Execution Trace:
ivalues . Wheni = 3ori = 6,i % 3 == 0evaluates to true, socontinueskips the print statement. Printed values:1 2 4 5.Answer: C (1 2 4 5)
M06: continue in a do-while loop
Project:
IT168_SA2_M06| Package:it168.sa2.m06| Class:QuestionM06Code Snippet:
java int n = 0; do { n++; if (n % 2 == 0) { continue; } System.out.print(n + " "); } while (n < 5); Execution Trace:
nbecomes1:1 % 2 == 0false, prints1, condition true.nbecomes2:2 % 2 == 0true,continueskips print, condition true.nbecomes3:3 % 2 == 0false, prints3, condition true.nbecomes4:4 % 2 == 0true,continueskips print, condition true.nbecomes5:5 % 2 == 0false, prints5, condition false -> loop terminates.Answer: A (1 3 5)
M07: Where break occurs
Project:
IT168_SA2_M07| Package:it168.sa2.m07| Class:QuestionM07Code Snippet:
java int total = 0; for (int n = 1; n <= 8; n++) { total += n; if (total >= 10) { break; } System.out.println(n + ":" + total); } System.out.println("Total=" + total); Execution Trace:
n = 1:total = 1, prints1:1n = 2:total = 3, prints2:3n = 3:total = 6, prints3:6n = 4:total = 10( true) ->breakterminates loop before printing4:10.Final print:
Total=10Answer: A ("1:1", then "2:3", then "3:6", then "Total=10")
M08: A sentinel and a filtered sum
Project:
IT168_SA2_M08| Package:it168.sa2.m08| Class:QuestionM08Input Tokens:
7 -2 4 0 99Code Snippet:
java Scanner input = new Scanner(System.in); int value = input.nextInt(); int count = 0; int sum = 0; while (value != 0) { count++; if (value > 0) { sum += value; } value = input.nextInt(); } System.out.println(count + " " + sum); Execution Trace:
Read
7:count = 1,sum = 7, read-2Read
-2:count = 2,sum = 7(not positive), read4Read
4:count = 3,sum = 11, read0Read
0: conditionvalue != 0fails, loop ends.Prints:
3 11(99remains unread).Answer: D ("3 11")
M09: Counting validation attempts
Project:
IT168_SA2_M09| Package:it168.sa2.m09| Class:QuestionM09Input Tokens:
-1 11 6 8Code Snippet:
java Scanner input = new Scanner(System.in); int value; int reads = 0; do { value = input.nextInt(); reads++; } while (value < 1 || value > 10); System.out.println(reads + ":" + value); Execution Trace:
Read
-1:reads = 1, condition true.Read
11:reads = 2, condition true.Read
6:reads = 3, condition false -> loop ends.Output:
3:6Answer: A ("3:6")
M10: A short-circuit guard
Project:
IT168_SA2_M10| Package:it168.sa2.m10| Class:QuestionM10Code Snippet:
java int divisor = 3; while (divisor != 0 && 12 / divisor > 2) { System.out.print(divisor + " "); divisor--; } Execution Trace:
divisor = 3: and (true), prints3,divisorbecomes2.divisor = 2: and (true), prints2,divisorbecomes1.divisor = 1: and (true), prints1,divisorbecomes0.divisor = 0:divisor != 0evaluates to false; short-circuit evaluation prevents12 / 0execution. Loop ends cleanly.Answer: D (It prints 3 2 1 and terminates normally.)
M11: Combining divisibility conditions
Project:
IT168_SA2_M11| Package:it168.sa2.m11| Class:QuestionM11Code Snippet:
java for (int i = 1; i <= 7; i++) { if (i % 2 == 0 || i % 3 == 0 && i > 4) { System.out.print(i + " "); } } Execution Trace: Precedence of
&&is higher than||. Condition is(i % 2 == 0) || ((i % 3 == 0) && (i > 4)).i = 1: falsei = 2: true -> prints2i = 3: false || (true && false) -> falsei = 4: true -> prints4i = 5: falsei = 6: true -> prints6i = 7: falseAnswer: D (2 4 6)
M12: Negating an interval test
Project:
IT168_SA2_M12| Package:it168.sa2.m12| Class:QuestionM12Code Snippet:
java int x = 9; int steps = 0; while (!(x >= 2 && x <= 4)) { x -= 2; steps++; } System.out.println(steps + " " + x); Execution Trace: Condition
!(x >= 2 && x <= 4)means loop continues whilex < 2orx > 4.x = 9: not in ->x = 7,steps = 1x = 7: not in ->x = 5,steps = 2x = 5: not in ->x = 3,steps = 3x = 3: -> condition false, loop ends.Output:
3 3Answer: B ("3 3")
M13: A rectangular nested loop
Project:
IT168_SA2_M13| Package:it168.sa2.m13| Class:QuestionM13Code Snippet:
java int visits = 0; for (int row = 1; row <= 4; row++) { for (int col = 2; col <= 7; col += 2) { visits++; } } System.out.println(visits); Execution Trace: Outer loop runs 4 times (
row= 1, 2, 3, 4). Inner loop runs 3 times per row (col= 2, 4, 6). Total iterations = .Answer: C (12)
M14: A changing inner bound
Project:
IT168_SA2_M14| Package:it168.sa2.m14| Class:QuestionM14Code Snippet:
java int visits = 0; for (int row = 1; row <= 4; row++) { for (int col = 1; col <= row; col += 2) { visits++; } } System.out.println(visits); Execution Trace:
row = 1:col = 1(1 visit)row = 2:col = 1(1 visit)row = 3:col = 1, 3(2 visits)row = 4:col = 1, 3(2 visits)Total
visits= .Answer: B (6)
M15: The order of nested iterations
Project:
IT168_SA2_M15| Package:it168.sa2.m15| Class:QuestionM15Code Snippet:
java for (int row = 1; row <= 2; row++) { for (int col = 1; col <= row + 1; col++) { System.out.print(row + "/" + col + " "); } } Execution Trace:
row = 1:colranges 1 to 2 -> prints1/1 1/2row = 2:colranges 1 to 3 -> prints2/1 2/2 2/3Answer: D (1/1 1/2 2/1 2/2 2/3)
M16: Skipping the diagonal
Project:
IT168_SA2_M16| Package:it168.sa2.m16| Class:QuestionM16Code Snippet:
java for (int row = 1; row <= 3; row++) { for (int col = 1; col <= 3; col++) { if (row == col) { continue; } System.out.print(col); } System.out.println(); } Execution Trace:
row = 1: skipcol = 1, print2,3->23row = 2: print1, skipcol = 2, print3->13row = 3: print1,2, skipcol = 3->12Answer: A ("23", then "13", then "12")
M17: Breaking only the inner loop
Project:
IT168_SA2_M17| Package:it168.sa2.m17| Class:QuestionM17Code Snippet:
int count = 0; for (int row = 1; row <= 3; row++) { for (int col = 1; col <= 4; col++) { if (row + col > 4) { break; } count++; } } System.out.println(count); ``` * **Execution Trace:** * `row = 1`: `col = 1, 2, 3` () -> `count` increases by 3; `col = 4` breaks. * `row = 2`: `col = 1, 2` () -> `count` increases by 2; `col = 3` breaks. * `row = 3`: `col = 1` () -> `count` increases by 1; `col = 2` breaks. * Total `count` = 3 + 2 + 1 = 6$.\n * **Answer:** B (6)\n\n* **M18: Skipping an entire row**\n * **Project:** `IT168_SA2_M18` | **Package:** `it168.sa2.m18` | **Class:** `QuestionM18`\n * **Code Snippet:**\n ```java\n int row = 0;\n while (row < 3) {\n row++;\n if (row == 2) {\n continue;\n }\n for (int col = 1; col <= row; col++) {\n System.out.print(row);\n }\n System.out.println();\n }\n ```\n * **Execution Trace:**\n * `row = 1`: prints `1`, then newline.\n * `row = 2`: `continue` skips loop body and newline.\n * `row = 3`: prints `333`, then newline.\n * **Answer:** A ("1", then "333")\n\n* **M19: An inner counter that is not reset**\n * **Project:** `IT168_SA2_M19` | **Package:** `it168.sa2.m19` | **Class:** `QuestionM19`\n * **Code Snippet:**\n ```java\n int col = 1;\n for (int row = 1; row <= 3; row++) {\n while (col <= 2) {\n System.out.print(col);\n col++;\n }\n System.out.println("#");\n }\n ```\n * **Execution Trace:**\n * `row = 1`: `col = 1` prints `1`, `col = 2` prints `2`, `col` becomes `3`. Prints `#`. Output: `12#`\n * `row = 2`: `col = 3`, 3 \le 2 false. Prints `#`. Output: `#`\n * `row = 3`: `col = 3`, 3 \le 2 false. Prints `#`. Output: `#`\n * **Answer:** C ("12#", then "#", then "#")\n\n* **M20: A subtotal for each row**\n * **Project:** `IT168_SA2_M20` | **Package:** `it168.sa2.m20` | **Class:** `QuestionM20`\n * **Code Snippet:**\n ```java\n for (int row = 1; row <= 3; row++) {\n int total = 0;\n for (int col = 1; col <= row; col++) {\n total += col;\n }\n System.out.print(total + " ");\n }\n ```\n * **Execution Trace:**\n * `row = 1`: `total` = 1 -> prints `1 `\n * `row = 2`: `total` = 1 + 2 = 3 -> prints `3 `\n * `row = 3`: `total` = 1 + 2 + 3 = 6 -> prints `6 `\n * **Answer:** C (1 3 6)\n\n* **M21: The scope of a for-loop variable**\n * **Project:** `IT168_SA2_M21` | **Package:** `it168.sa2.m21` | **Class:** `QuestionM21`\n * **Code Snippet:**\n ```java\n for (int k = 0; k < 3; k++) {\n System.out.print(k + " ");\n }\n System.out.println(k);\n ```\n * **Explanation:** `k` is declared in the `for` loop header and its scope is limited to the loop block. Referencing `k` outside the loop causes a compilation error.\n * **Answer:** B (It does not compile because k is out of scope in the final statement.)\n\n* **M22: The end of a do-while statement**\n * **Project:** `IT168_SA2_M22` | **Package:** `it168.sa2.m22` | **Class:** `QuestionM22`\n * **Code Snippet:**\n ```java\n int n = 3;\n do {\n System.out.println(n);\n n--;\n } while (n > 0)\n ```\n * **Explanation:** A `do-while` statement requires a terminating semicolon `;` after the condition expression `while (n > 0);`. Without it, the code fails to compile.\n * **Answer:** C (It does not compile because the do-while statement lacks its ending semicolon.)\n\n* **M23: The type of a loop condition**\n * **Project:** `IT168_SA2_M23` | **Package:** `it168.sa2.m23` | **Class:** `QuestionM23`\n * **Code Snippet:**\n ```java\n int count = 3;\n while (count) {\n System.out.println(count);\n count--;\n }\n ```\n * **Explanation:** Java requires a expression evaluating to type `boolean` in control conditions. Passing an integer expression like `count` results in a compilation error.\n * **Answer:** C (It does not compile because the condition has type int, not boolean.)\n\n* **M24: An error after several iterations**\n * **Project:** `IT168_SA2_M24` | **Package:** `it168.sa2.m24` | **Class:** `QuestionM24`\n * **Code Snippet:**\n ```java\n for (int divisor = 3; divisor >= 0; divisor--) {\n System.out.print(12 / divisor + " ");\n }\n ```\n * **Execution Trace:** `divisor = 3` prints `4 `, `divisor = 2` prints `6 `, `divisor = 1` prints `12 `. When `divisor = 0`, evaluating `12 / 0` throws an `ArithmeticException` at runtime.\n * **Answer:** A (It prints 4 6 12, then integer division by zero causes a runtime error.)\n\n* **M25: An extra semicolon**\n * **Project:** `IT168_SA2_M25` | **Package:** `it168.sa2.m25` | **Class:** `QuestionM25`\n * **Code Snippet:**\n ```java\n int k;\n for (k = 1; k <= 3; k++); {\n System.out.println(k);\n }\n ```\n * **Execution Trace:** The semicolon `;` immediately following the `for` header acts as an empty statement body. The loop iterates until `k = 4`. Afterwards, the independent block `{ System.out.println(k); }` executes once, printing `4`.\n * **Answer:** B (4 on one line)\n\n* **M26: A skipped update**\n * **Project:** `IT168_SA2_M26` | **Package:** `it168.sa2.m26` | **Class:** `QuestionM26`\n * **Code Snippet:**\n ```java\n int n = 2;\n while (n < 8) {\n if (n % 2 == 0) {\n continue;\n }\n n++;\n }\n System.out.println(n);\n ```\n * **Execution Trace:** `n = 2`. 2 \% 2 == 02 < 8. `n` remains 2, creating an infinite loop.\n * **Answer:** C (It compiles, but never reaches the print statement because n stays 2.)\n\n* **M27: A String loop boundary**\n * **Project:** `IT168_SA2_M27` | **Package:** `it168.sa2.m27` | **Class:** `QuestionM27`\n * **Code Snippet:**\n ```java\n String text = "LOOP";\n for (int i = 0; i <= text.length(); i++) {\n System.out.print(text.charAt(i));\n }\n ```\n * **Execution Trace:** `text.length()` returns 4. Valid indices are 0 to 3. Loop iterates `i` from 0 to 4 (`i <= 4`). Prints `L`, `O`, `O`, `P`. When `i = 4`, `text.charAt(4)` throws a `StringIndexOutOfBoundsException` at runtime.\n * **Answer:** D (It prints LOOP, then an out-of-bounds character access causes a runtime error.)\n\n* **M28: Rows with no inner iterations**\n * **Project:** `IT168_SA2_M28` | **Package:** `it168.sa2.m28` | **Class:** `QuestionM28`\n * **Code Snippet:**\n ```java\n for (int row = 3; row >= 1; row--) {\n for (int col = row; col < 3; col++) {\n System.out.print(col);\n }\n System.out.print("|");\n }\n ```\n * **Execution Trace:**\n * `row = 3`: inner condition 3 < 3 false (0 iterations) -> prints `|`\n * `row = 2`: inner condition 2 < 3 true -> prints `2`, loop ends -> prints `|`\n * `row = 1`: inner condition 1 < 32 < 3 prints `2` -> prints `12`, loop ends -> prints `|`\n * Total output: `|2|12|`\n * **Answer:** B ("|2|12|")\n\n* **M29: Changing the control variable in the body**\n * **Project:** `IT168_SA2_M29` | **Package:** `it168.sa2.m29` | **Class:** `QuestionM29`\n * **Code Snippet:**\n ```java\n for (int i = 1; i <= 7; i++) {\n if (i % 2 == 1) {\n i++;\n }\n System.out.print(i + " ");\n }\n ```\n * **Execution Trace:**\n * `i = 1`: odd -> `i++` makes `i = 2`, prints `2 `, loop increment makes `i = 3`.\n * `i = 3`: odd -> `i++` makes `i = 4`, prints `4 `, loop increment makes `i = 5`.\n * `i = 5`: odd -> `i++` makes `i = 6`, prints `6 `, loop increment makes `i = 7`.\n * `i = 7`: odd -> `i++` makes `i = 8`, prints `8 `, loop increment makes `i = 9` (9 \le 7 false) -> loop ends.\n * **Answer:** B (2 4 6 8)\n\n* **M30: Turning row and column tests into a pattern**\n * **Project:** `IT168_SA2_M30` | **Package:** `it168.sa2.m30` | **Class:** `QuestionM30`\n * **Code Snippet:**\n ```java\n for (int row = 1; row <= 3; row++) {\n for (int col = 1; col <= 4; col++) {\n if (col <= row) {\n System.out.print(row);\n } else {\n System.out.print(".");\n }\n }\n System.out.println();\n }\n ```\n * **Execution Trace:**\n * `row = 1`: `col = 1` prints `1`, `col = 2,3,4` prints `.` -> `1...`\n * `row = 2`: `col = 1,2` prints `2`, `col = 3,4` prints `.` -> `22..`\n * `row = 3`: `col = 1,2,3` prints `3`, `col = 4` prints `.` -> `333.`\n * **Answer:** A ("1...", then "22..", then "333.")\n\n# Section B: Short Answer Questions and Trace Analyses\n\n* **S01: Trace a changing remainder**\n * **Project:** `IT168_SA2_S01` | **Package:** `it168.sa2.s01` | **Class:** `QuestionS01`\n * **Snippet:**\n ```java\n int n = 10;\n int total = 0;\n while (n > 1) {\n total += n % 3;\n System.out.println(n + " " + total);\n n -= 3;\n }\n System.out.println("End:" + n);\n ```\n * **(a) Trace Table:**\n\n| Iteration | `n` at entry | `n % 3` | `total` after addition | `n` after update |\n| :--- | :--- | :--- | :--- | :--- |\n| 1 | 10 | 1 | 1 | 7 |\n| 2 | 7 | 1 | 2 | 4 |\n| 3 | 4 | 1 | 3 | 1 |\n\n * **(b) Output and Body Executions:**\n * Output:\n ```text\n 10 1\n 7 2\n 4 3\n End:1\n ```\n * Loop-body executions: 3 times.\n\n* **S02: Body executions versus condition checks**\n * **Project:** `IT168_SA2_S02` | **Package:** `it168.sa2.s02` | **Class:** `QuestionS02`\n * **Snippet:**\n ```java\n int n = 1;\n int total = 0;\n do {\n total += n;\n System.out.println(n + ":" + total);\n n *= 2;\n } while (total < 10);\n ```\n * **(a) Output and Final Values:**\n * Output:\n ```text\n 1:1\n 2:3\n 4:7\n 8:15\n ```\n * Final values: `n = 16`, `total = 15`.\n * **(b) Execution and Evaluation Counts:**\n * Loop body executions: 4 times.\n * Condition evaluations (`total < 10`): 4 times.\n * Explanation: In a post-test `do-while` loop, the body executes unconditionally on the first pass before evaluating the condition. Each subsequent pass executes the body and tests the condition at the end. Thus, body executions match condition evaluations.\n\n* **S03: Translate for into while**\n * **Project:** `IT168_SA2_S03` | **Package:** `it168.sa2.s03` | **Class:** `QuestionS03`\n * **Snippet:**\n ```java\n int i;\n int sum = 0;\n for (i = 2; i <= 11; i += 3) {\n sum += i;\n System.out.println(i + ":" + sum);\n }\n System.out.println("Final:" + i);\n ```\n * **(a) Complete Output:**\n ```text\n 2:2\n 5:7\n 8:15\n 11:26\n Final:14\n ```\n * **(b) Equivalent while loop:**\n ```java\n int i = 2;\n int sum = 0;\n while (i <= 11) {\n sum += i;\n System.out.println(i + ":" + sum);\n i += 3;\n }\n System.out.println("Final:" + i);\n ```\n\n* **S04: Preserve a zero-iteration case**\n * **Project:** `IT168_SA2_S04` | **Package:** `it168.sa2.s04` | **Class:** `QuestionS04`\n * **Snippet:**\n ```java\n while (n > 0) {\n System.out.println(n);\n n--;\n }\n ```\n * **(a) Equivalent Guarded do-while Structure:**\n ```java\n if (n > 0) {\n do {\n System.out.println(n);\n n--;\n } while (n > 0);\n }\n ```\n * **(b) Evaluation for Initial Values 0 and 3:**\n * Initial `n = 0`: Produces no output; final `n = 0`.\n * Initial `n = 3`: Prints `3`, `2`, `1` on separate lines; final `n = 0`.\n * Explanation: An unguarded `do-while` loop executes its body at least once before testing the loop condition. If `n = 0`, an unguarded `do-while` would execute the body, printing `0` and reducing `n` to `-1`, violating original behavior.\n\n* **S05: Sentinel, rejected input, and unread input**\n * **Project:** `IT168_SA2_S05` | **Package:** `it168.sa2.s05` | **Class:** `QuestionS05`\n * **Input Tokens:** `8 -4 0 5 -99 7`\n * **Snippet:**\n ```java\n Scanner input = new Scanner(System.in);\n int count = 0;\n int total = 0;\n while (true) {\n int value = input.nextInt();\n if (value == -99) {\n break;\n }\n if (value < 0) {\n continue;\n }\n count++;\n total += value;\n }\n System.out.println(count + ":" + total);\n ```\n * **(a) Output and Categorization:**\n * Output: `3:13`\n * Accepted values: `8`, `0`, `5`\n * Rejected value: `-4`\n * Sentinel value: `-99`\n * **(b) Loop Entries and Unread Tokens:**\n * Loop body entries: 5 times (for tokens `8`, `-4`, `0`, `5`, `-99`).\n * Unread token: `7`.\n\n* **S06: Preserve continue during loop conversion**\n * **Project:** `IT168_SA2_S06` | **Package:** `it168.sa2.s06` | **Class:** `QuestionS06`\n * **(a) Output:** `1 3 5 `\n * **(b) Equivalent while loop:**\n ```java\n int i = 1;\n while (i <= 6) {\n if (i % 2 == 0) {\n i++;\n continue;\n }\n System.out.print(i + " ");\n i++;\n }\n ```\n * Explanation: In a `for` loop, the update statement (`i++`) executes automatically after `continue`. In a `while` loop, the increment must explicitly precede `continue` inside the conditional block to prevent an infinite loop.\n\n* **S07: continue and the bottom test**\n * **Project:** `IT168_SA2_S07` | **Package:** `it168.sa2.s07` | **Class:** `QuestionS07`\n * **Snippet:**\n ```java\n int n = 5;\n do {\n n--;\n if (n == 3) {\n continue;\n }\n System.out.println(n);\n } while (n > 1);\n ```\n * **(a) Complete Output and Final `n`:**\n * Output:\n ```text\n 4\n 2\n 1\n ```\n * Final `n = 1`.\n * **(b) Iteration Breakdown:**\n * Iteration 1: `n` decreases to `4`. Prints `4`. Test 4 > 1 is true.\n * Iteration 2: `n` decreases to `3`. `continue` triggers. Printing is skipped. Test 3 > 1 is true.\n * Iteration 3: `n` decreases to `2`. Prints `2`. Test 2 > 1 is true.\n * Iteration 4: `n` decreases to `1`. Prints `1`. Test 1 > 1 is false. Loop ends.\n * Answer: `continue` does **not** skip the bottom condition test; it jumps directly to evaluating `while (n > 1)`.\n\n* **S08: Repair a sentinel average**\n * **Project:** `IT168_SA2_S08` | **Package:** `it168.sa2.s08` | **Class:** `QuestionS08`\n * **(a) Flaw Analysis:**\n * For input `6 10 -1`: The loop adds `-1` to `total` (6 + 10 - 1 = 1515 / 3 = 5.0(6+10)/2 = 8.0.\n * For input `-1`: The loop adds `-1` to `total` and sets `count` to `1`, computing -1.0$$ instead of detecting empty input. * **(b) Repaired Implementation:**java_standalone Scanner input = new Scanner(System.in); int value = input.nextInt(); int total = 0; int count = 0; while (value != -1) { total += value; count++; value = input.nextInt(); } if (count == 0) { System.out.println("No data"); } else { System.out.println((double) total / count); } ```
S09: Separate compilation and boundary errors
Project:
IT168_SA2_S09| Package:it168.sa2.s09| Class:QuestionS09(a) Analysis:
Does not compile.
iis declared in theforloop header, making it out of scope in `System.out.println(