← ICS3U Computer Science
ICS3U · Exam review
Computer Science Exam Review
A practice exam with questions from all 7 units, then the key facts from every lesson, unit by unit. For a deeper look at one unit, open its test review.
Unit test reviews
Practice exam
35 questions, the same number from each unit. Each one shows the lesson it comes from.
- Unit 1: Components, Specifications and Building to a Need1A user edits 4K video and complains the timeline stutters whenever effects are added. Which upgrade addresses the most likely bottleneck?
- Unit 1: Components, Specifications and Building to a Need2Why is electrostatic discharge damage especially frustrating to diagnose?
- Unit 1: How Computers Represent Data3The ASCII code for 'M' is 77. What is the ASCII code for 'm'?
- Unit 1: Files, Folders and a Workspace That Works4Put these file names in the order a computer would sort them alphabetically.
- 1lab3.java
- 2lab20.java
- 3lab2.java
- 4lab1.java
- 5lab10.java
- Unit 1: Files, Folders and a Workspace That Works5Which statement about compression is correct?
- Unit 2: Your First Java Program6Which of these is the correct signature for the method where a Java program starts?
- Unit 2: Your First Java Program7What file does
javac Hello.javaproduce? - Unit 2: Variables, Primitive Types and Casting8What does
System.out.println(5 / 2.0);print? - Unit 2: Operators, Expressions and Input9What does
10 % 4 * 2evaluate to? - Unit 2: Operators, Expressions and Input10Order these steps as Java evaluates
2 + 3 * 4 - 6 / 2.- 1Evaluate 6 / 2, giving 3
- 2Subtract 3 from 14, giving 11
- 3Add 2 + 12, giving 14
- 4Evaluate 3 * 4, giving 12
- Unit 3: Boolean Expressions and Comparison11Which line correctly tests whether the String
answerholds the text yes? - Unit 3: Boolean Expressions and Comparison12Given
String a = "cat";andString c = new String("cat");, what doesa == cproduce? - Unit 3: if, else if and else13What is wrong with
if (total > 100);followed by a block that prints a discount? - Unit 3: switch, Validation and Choosing a Structure14In a switch with cases 1, 2, 3 and default, all printing their own word and none having a break, what is printed when the selector is 3?
- Unit 3: switch, Validation and Choosing a Structure15Why should a validation message say what would be acceptable, not just that something is wrong?
- Unit 4: while and do-while16A loop prints the same value forever. Which part is most likely missing?
- Unit 4: while and do-while17Put the parts of a correct sentinel-controlled input loop in order.
- 1Prompt and read the next value at the end of the body
- 2Update the accumulator with the current value
- 3Report the result after the loop finishes
- 4Initialize the accumulator before the loop
- 5Prompt and read the first value (the priming read)
- 6Test the value against the sentinel in the loop condition
- Unit 4: for Loops and Counting18Why can an enhanced for loop
for (int mark : marks)never throw an ArrayIndexOutOfBoundsException? - Unit 4: Accumulators, Counters and Nested Loops19What is the final value of
product?int product = 1; for (int i = 1; i <= 5; i++) { product = product * i; } - Unit 4: Accumulators, Counters and Nested Loops20A nested loop prints every item on its own line instead of in rows. What is wrong?
- Unit 5: Writing and Calling Methods21What does a return type of
voidtell you about a method? - Unit 5: Writing and Calling Methods22Given
public static int triple(int n) { return n * 3; }, what is printed bySystem.out.println(triple(4) + triple(2));? - Unit 5: Parameters, Arguments and Scope23What is printed?
int total = 0; for (int i = 1; i <= 3; i++) { int d = i * 2; total += d; } System.out.println(total); - Unit 5: Decomposition and Program Design24Order the steps of top-down design.
- 1Write stubs so the program compiles and runs
- 2Name each piece with a verb and write its signature
- 3Replace one stub at a time, testing after each
- 4State the whole job in one sentence
- 5Split it into a handful of major steps
- 6Split any step that is still too big to write directly
- Unit 5: Decomposition and Program Design25Which principle says that the same logic should not be written out in several places?
- Unit 6: Declaring and Using Arrays26For
int[] a = {5, 10, 15, 20};, what is the value ofa[1]? - Unit 6: Traversing Arrays and the Standard Algorithms27By convention, what value does a linear search return when the target is not in the array?
- Unit 6: Sorting and Binary Search28
binarySearch(d, 21)runs on{3, 8, 12, 17, 21, 26, 30, 34, 41, 45, 52, 58, 63, 70, 77}. Put the elements it checks in the order it checks them.- 1d[3] = 17
- 2d[4] = 21
- 3d[5] = 26
- 4d[7] = 34
- Unit 6: Strings as Sequences of Characters29Put these Strings in the order
compareTosorts them, smallest first.- 1"apple"
- 2"banana"
- 3"apples"
- 4"Zebra"
- Unit 6: Two-Dimensional Arrays30What does
String[][] board = new String[3][3];contain immediately after creation? - Unit 7: The Software Development Life Cycle31Order the stages of the software development life cycle.
- 1Maintenance
- 2Testing
- 3Implementation
- 4Analysis and requirements
- 5Design
- Unit 7: Problem-Solving, Pseudocode and Algorithm Design32A program must calculate a subtotal, apply a discount and then add 13 percent HST. In which order must the steps run?
- Unit 7: Code Style, Conventions and Maintainable Code33Using CheckoutTotal (discount 10 percent at 35 dollars or more, then 13 percent HST), what total is printed for a cart whose prices add up to 30.00 dollars? Give the answer to 2 decimal places.dollars
- Unit 7: Computing and Environmental Stewardship34A 350 W gaming PC runs 3 hours a day for 365 days. How many kilowatt-hours does it use? Round to 2 decimal places.kWh
- Unit 7: Emerging Research and Careers in Computing35Which portfolio is strongest for a computing application?
Key facts by unit
Unit 1: Intro to Computers
Components, Specifications and Building to a Need
- Bottleneck rule: for any one workload, the slowest component involved sets the performance — spend there first.
- Compatibility gates, in order: CPU socket matches the motherboard, RAM generation matches the board, PSU wattage covers the load, case clears the GPU and cooler.
- PSU sizing: add the CPU and GPU draw, add about 75 W for everything else, then multiply by roughly 1.3 for headroom.
- SATA III caps at 6 Gb/s, about 550 MB/s of real data; NVMe uses PCIe lanes directly and reaches several GB/s.
- Dual channel doubles memory bandwidth, so two matched sticks beat one stick of the same total capacity.
- Electrostatic discharge can damage a component invisibly today and cause a failure weeks later — ground yourself before touching anything.
How Computers Represent Data
- Binary place values from the right: — doubling each time.
- An -bit pattern has possible values: unsigned they run to , signed they run to .
- 8 bits = 1 byte, and 4 bits = exactly 1 hex digit because .
- Java int is 32 bits signed, so its range is to ; exceeding it wraps around silently.
- 1 KiB = 1024 bytes but 1 kB = 1000 bytes; lowercase b is bits, uppercase B is bytes.
- ASCII: A is 65, a is 97 (always 32 apart), and the character 0 is 48.
Files, Folders and a Workspace That Works
- An absolute path starts at the root and always means the same file; a relative path starts at the current working directory and survives moving the project.
- In a relative path,
.is the current folder and..is the parent folder. - A file's real type is determined by its content (its signature bytes), not by its extension — renaming converts nothing.
- Name files so they sort: ISO dates (YYYY-MM-DD), zero-padded numbers, no spaces.
- 3-2-1 backup: three copies, on two kinds of media, with one offsite.
- Lossless compression restores the original exactly; lossy compression discards detail permanently.
Unit 2: Programming Basics
Your First Java Program
- Every Java program lives in a class, and execution starts at
public static void main(String[] args). - The file name must exactly match the public class name, including capitals:
public class Hellogoes in Hello.java. - Braces
{ }group statements into blocks; a semicolon;ends one statement. Braces take no semicolon. javac Hello.javacompiles to Hello.class;java Helloruns it — no file extension on the run command.printlnprints then moves to a new line;printprints and leaves the cursor in place.- Three error types: syntax (caught at compile time), runtime (crashes mid-run), logic (runs fine, answer is wrong).
Variables, Primitive Types and Casting
- The eight primitives are
byte,short,int,long,float,double,char,boolean.Stringis a class, not a primitive. intholds up to ; going past it wraps silently to the most negative int.- If both operands of
/are integers, Java truncates:5 / 2is2. Make one side a double to get 2.5. %gives the remainder:17 % 5is2, andn % 2 == 0tests for even.- Widening (byte → short → int → long → float → double) is automatic; narrowing needs a cast such as
(int). - A cast truncates toward zero —
(int) 9.99is9— andfinalconstants are written in UPPER_SNAKE_CASE.
Operators, Expressions and Input
- Precedence: brackets, then unary, then
* / %left to right, then+ -left to right, then assignment. %sits at the same level as*and/, so10 % 4 * 2is(10 % 4) * 2 = 4.- If either operand of
+is a String,+joins:"total: " + 1 + 2givestotal: 12, so bracket the arithmetic. x += 3meansx = x + 3;x++uses the old value then increments,++xincrements then uses the new one.Math.roundreturns along; to round to two decimals useMath.round(v * 100) / 100.0with a double divisor.- After
nextInt()ornextDouble(), call a barenextLine()before reading a line of text.
Unit 3: If Statements
Boolean Expressions and Comparison
- A
booleanis onlytrueorfalse; Java will not accept a number or a String where a condition is required. - The six relational operators are
==,!=,<,>,<=,>=, and each produces a boolean. &&needs both sides true,||needs at least one,!flips. Precedence runs!, then&&, then||.- Short-circuit:
&&skips its right side when the left is false, so a guard such ascount != 0 &&must come first. - De Morgan: and .
=assigns and==compares; for Strings use.equals(), because==compares references.
if, else if and else
- An
ifruns its block only when the condition istrue; the optionalelseblock runs in every other case. - Without braces, an
ifcontrols only the very next statement — always write the braces anyway. - An
else ifchain stops at the first true condition, so overlapping ranges must go from most demanding to least. - Exactly one branch of an if / else if / else chain ever runs, and the rest are skipped without being tested.
- An
elsebinds to the nearest unmatchedif, regardless of indentation. - The ternary
condition ? valueIfTrue : valueIfFalseis an expression that produces one of two values.
switch, Validation and Choosing a Structure
switchcompares one selector against fixedcaseconstants;defaulthandles everything unmatched.breakexits the switch. Without it, execution falls through into the statements of the cases below.- Stacked bare labels such as
case 4: case 6:are deliberate fall-through and share one block. - A switch selector may be
int,short,byte,char,Stringor an enum — neverdouble,float,longorboolean. - Use
switchfor a list of fixed values andelse iffor ranges, decimals or multi-variable conditions. - Integer division by zero throws ArithmeticException; double division by zero gives Infinity or NaN silently.
Unit 4: Looping
while and do-while
- Every loop needs three parts: initialize before, a condition to test, and an update inside the body.
- A while loop tests first, so its body can run zero times.
- A do-while loop tests last, so its body always runs at least once, and its condition is followed by a semicolon.
- An infinite loop means the condition never becomes false — the update is almost always missing or wrong.
- A sentinel loop needs a priming read before the loop and another read at the end of the body.
count++is shorthand forcount = count + 1, andtotal += valueis shorthand fortotal = total + value.
for Loops and Counting
for (init; condition; update)— the initialization runs once, then the cycle is test, body, update, test.for (int i = 0; i < n; i++)runs exactly times, with taking the values to .- Counting by 1 from to inclusive runs times.
- A variable declared in the for header exists only inside the loop — using it afterwards will not compile.
- Use
forwhen the number of passes is known in advance,whilewhen it is not. - The enhanced for loop
for (int x : arr)gives you each value but no index.
Accumulators, Counters and Nested Loops
- Declare and initialize an accumulator before the loop; change it inside. Declaring it inside resets it every pass.
- A sum starts at 0, a product starts at 1, and a counter starts at 0.
- A max or min tracker starts at the first element, and its loop then starts at index 1.
- When both bounds are fixed, total inner passes = outer passes inner passes.
- When the inner bound depends on the outer counter, add the pass counts instead of multiplying.
breakexits the loop immediately;continueskips to the next pass. Both affect only the innermost loop containing them.
Unit 5: Methods
Writing and Calling Methods
- A signature is: access modifier,
static, return type, name, then the parameter list in brackets. voidmeans the method hands nothing back; any other return type demands areturnon every path.returnsupplies the value and ends the method immediately — nothing after it runs.- A call pauses the current line, runs the method, and resumes at exactly the same point with the returned value.
- Method names are camelCase verbs starting with a lowercase letter:
calculateAverage, notCalculateAverageoravg. - Methods are written inside the class but outside every other method; they can never be nested.
Parameters, Arguments and Scope
- A parameter is in the definition and has a type; an argument is at the call and is a value.
- Java matches arguments to parameters by position — number, order and type must all agree.
- Java is pass by value: a primitive argument is copied, so reassigning the parameter never changes the caller's variable.
- To make a change stick, return the new value and assign it:
score = addTen(score); - A variable exists from its declaration to the closing brace of its block, and nowhere else.
- Overloading means same name, different parameter list. A different return type alone is not enough.
Decomposition and Program Design
- One method, one job — if you need the word "and" to describe it, split it.
- Method names are verbs or verb phrases in camelCase; boolean methods start with
isorhas. - Top-down design: split the job into steps, then split any step that is still too big, before writing any logic.
- A stub has the correct signature and a placeholder body so the program compiles and runs while it is unfinished.
- Test one method at a time as you replace each stub, so any new bug is in the piece you just wrote.
- Every method called directly from
mainmust bestatic, becausemainruns without an object.
Unit 6: Arrays
Declaring and Using Arrays
int[] a = new int[n];creates n slots filled with the default value;int[] a = {1, 2, 3};creates and fills in one step.- Indexes start at 0, so the valid range is 0 to and the last element is
a[a.length - 1]. - Arrays use
.lengthwith no brackets; Strings use.length()with brackets. - Defaults: 0 for whole numbers, 0.0 for decimals, false for boolean, null for String and other objects.
- An array's length is fixed at creation and can never change.
- Any index below 0 or at least equal to the length throws ArrayIndexOutOfBoundsException.
Traversing Arrays and the Standard Algorithms
- The standard traversal is
for (int i = 0; i < arr.length; i++)— strict less-than, never<=. - Use for-each when you need only the values; use the index loop when you must modify elements or report a position.
- Assigning to a for-each loop variable changes a copy and leaves the array unchanged.
- Initialize a max or min search with
arr[0], never with 0, then loop from index 1. - A linear search returns the index on a match and −1 after the loop if nothing matched.
- Swapping needs a temporary variable, and reversing swaps from both ends inwards for
length / 2passes.
Sorting and Binary Search
- Selection sort: each pass finds the smallest unsorted value and swaps it into the next slot; n elements need n − 1 passes and n(n − 1)/2 comparisons.
- Bubble sort: each pass swaps out-of-order neighbours, carrying the largest remaining value to the end; a pass with no swaps means the array is sorted.
- Swapping two elements always needs a temporary variable: save, copy over, restore.
- Java passes arguments by value, but an array variable's value is a reference, so a method can change the caller's elements — not which array the caller's variable points to.
- Binary search requires sorted data; it checks the middle, then discards half the range, using
low = mid + 1orhigh = mid - 1. - Worst-case binary search on n elements needs floor(log₂ n) + 1 checks — 20 for a million elements, against a million for linear search.
Strings as Sequences of Characters
- String characters are indexed from 0 to
s.length() - 1;length()is a method with brackets, unlike an array'slengthfield. s.charAt(i)returns achar;s.substring(a, b)returns the characters from index a up to but not including b, so its length is b − a.s.indexOf(x)returns the index of the first occurrence of x, or −1 if it is absent.- Strings are immutable:
toUpperCase,toLowerCaseandsubstringreturn new Strings, so store the result. - Use
equalsorequalsIgnoreCasefor matching text, andcompareTofor order: negative means first, 0 means equal, positive means after. - A position outside 0 to length − 1 throws StringIndexOutOfBoundsException.
Two-Dimensional Arrays
int[][] grid = new int[3][4];makes 3 rows of 4 columns — 12 cells, all starting at 0.- A cell is
grid[row][col]: row first, column second, both counting from 0. grid.lengthis the number of rows;grid[0].lengthis the number of columns.- Nested loops traverse a grid — outer loop over rows, inner loop over columns.
- The inner body runs rows times columns times in total, so a 3 by 4 grid means 12 passes.
- Java stores grids in row-major order: all of row 0, then all of row 1, and so on.
Unit 7: Software Development & the CPT
The Software Development Life Cycle
- The stages are analysis, design, implementation, testing and maintenance — in that order, and maintenance loops back to analysis.
- A requirement must be checkable: if you cannot name a test for it, rewrite it.
- Functional requirements say what the program does; non-functional say how well it must do it.
- Waterfall completes each stage once; iterative repeats all the stages on small slices to get feedback early.
- A defect found after release costs roughly 30 times what it costs at the analysis stage.
- Maintenance consumes the majority of a successful program's total effort.
Problem-Solving, Pseudocode and Algorithm Design
- Decomposition splits a problem into independent sub-problems; pattern recognition spots the ones you have already solved.
- Abstraction means deliberately ignoring detail that does not affect the solution.
- An IPO chart lists inputs, processing and outputs, and exposes values that were never actually supplied.
- Pseudocode is structured English with no syntax rules; it exists so the logic can be checked cheaply.
- In a flowchart, a diamond is a decision and must have exactly two exits, both of which lead somewhere.
- Boundary words in a specification — inclusive, at least, up to — decide between
<and<=.
Testing, Debugging and Documentation
- Every test set needs normal, boundary and invalid cases; boundary cases find the most bugs.
- Test the boundary value, one below it and one above it — that is where
<and<=disagree. - Syntax errors stop compilation, runtime errors stop execution, logic errors produce a wrong answer in silence.
- A stack trace gives the exception type, the message, and the exact file and line where it stopped.
- A trace table finds logic errors by executing the code by hand exactly as written.
- Comments should explain why, not what; the code already says what.
Code Style, Conventions and Maintainable Code
- Classes use UpperCamelCase, methods and variables use lowerCamelCase, and constants use UPPER_SNAKE_CASE.
- Indent one level (usually four spaces) per block so the layout on screen matches the logic.
- Replace magic numbers with
finalnamed constants, declared once, so a change of value is a one-line edit. - Comments explain WHY; every file gets a header comment and every method a Javadoc comment (
/** ... */with@paramand@return). - Refactoring changes structure without changing behaviour: one small change at a time, re-testing after each.
- Commit small, working versions with messages that say what changed and why, and use branches for risky changes.
The Culminating Project, Society and Careers
- Scope a project by sorting features into must, should, could and will-not have, and build strictly in that order.
- A milestone must be provable by running something, not by an estimate of how complete it feels.
- Reserve about a fifth of your time for testing, fixing and documentation.
- Manufacturing a device usually costs more energy than the electricity it will consume in its whole life, so extending lifespan is the strongest environmental lever.
- E-waste contains both hazardous materials and recoverable metals, so it must go to a designated recycling program.
- Ontario pathways include university computer science or engineering, college programming and IT, combined transfer routes, and certification.
Computing and Environmental Stewardship
- Energy in kWh = power in watts ÷ 1000 × hours of use; cost = kWh × the rate per kWh (about 0.12 dollars in Ontario, approximately).
- For laptops and phones, manufacturing is usually the largest part of the lifetime footprint, so keeping devices longer is the strongest lever.
- Power-management policies (display off, sleep, overnight shutdown) save the most for the least effort, because most computers are idle most of the time.
- ENERGY STAR certifies energy efficiency; EPEAT rates the whole life cycle in Bronze, Silver and Gold tiers.
- In Ontario, producers are responsible for collecting and recycling electronics; use municipal depots, retailer take-back or producer drop-off programs.
- Deleting or formatting does not erase data: wipe, secure-erase or crypto-erase storage, or destroy it, before disposal.
Emerging Research and Careers in Computing
- Machine learning trains a model on labelled examples and must be tested on data it has never seen; biased or unrepresentative data produces biased results.
- A register of n qubits is described by 2ⁿ numbers, but quantum computers help only with certain problems; post-quantum encryption is being adopted before they arrive.
- Cybersecurity, HCI and bioinformatics each combine computing with another discipline: law and criminology, psychology and design, or biology and medicine.
- Moore's law — transistor counts doubling about every two years — has slowed, pushing progress toward specialized hardware and better algorithms.
- Ontario university computer science programs commonly require ENG4U, MHF4U and MCV4U; college programs typically require Grade 12 English and math.
- A portfolio of two or three finished, documented, published projects is the strongest evidence of interest and skill.