Programming Companion
Java

Programming technique

Sequence and output

A program normally executes statements from top to bottom. Changing the order can change the result, even when every individual statement is valid.

IB DP CS standard B2.3.1: Construct programs that implement the correct sequence of code instructions to meet program objectives.

Output one line at a time

System.out.println() displays a value and then moves to a new line. The statements below produce three lines in exactly the order written.

print() displays a value and then moves to a new line. The statements below produce three lines in exactly the order written.

Console output
System ready
Temperature: 21 C
Doors locked

Continue on the same line

System.out.print() does not move to a new line. It is useful when several statements contribute to one line of output.

By default, print() ends with a newline. Set end="" when several statements should contribute to the same line.

Console output
Loading... complete

Comments

Java uses // for a single-line comment. A useful comment explains a purpose, decision or section of the program. Avoid comments that merely repeat obvious syntax.

Python uses # for a single-line comment. A useful comment explains a purpose, decision or section of the program. Avoid comments that merely repeat obvious syntax.

Order matters

Read the program from top to bottom and predict every line of output before running it.

Exact text matters

Capital letters, punctuation and spaces inside quotation marks all form part of the output.

Semicolons matter

Each Java statement ends with a semicolon.

Line structure matters

Python normally places one statement on each line and does not require a semicolon.

Challenges Choose one

Choose a challenge that feels appropriate for you. Code heat is only a rough estimate, not a fixed level.

Visual Dice

Challenge ID: PC-T01-C01 · Standards: B2.3.1

Write a program that outputs a large number 5 as the face of a die. Use only text characters and make the border and spots line up clearly.

Two white dice with black pips.

ASCII Name

Challenge ID: PC-T01-C02 · Standards: B2.3.1

Write a program that outputs your name as ASCII art. Plan the final picture first, then reproduce it using a sequence of print statements.

A terminal window displaying a cat made from text characters.

Console Profile Card

Challenge ID: PC-T01-C03 · Standards: B2.3.1

Create a neatly aligned console profile card containing a name, favourite subject, current project and one-line motto. Include a border and purposeful comments that explain sections rather than obvious individual lines.

Console Poster

Challenge ID: PC-T01-C04 · Standards: B2.3.1

Design a detailed console poster for an event, game or club. It must use at least 15 output statements, preserve exact spacing and order, and include a short test checklist describing what the finished output should look like.