1. Reference Guide

Key Topics


Term Definition Example
Output Information the program shows the user. System.out.println("Hi");
String literal Text written inside double quotes. "Hello"
Escape sequence A backslash plus a character, for characters a string cannot hold directly. "Line 1\nLine 2"
Arithmetic expression Numbers and operators that work out to one value. 2 + 3 * 4
Integer division int / int keeps only the whole-number part. 7 / 2 is 3
Remainder % gives what is left over after dividing. 7 % 2 is 1
Concatenation + joins a String with another value. "Age: " + 16
  • + adds numbers but joins Strings, and Java works left to right
  • Dividing an int by 0 compiles, then throws an ArithmeticException

Key Takeaways

  • Output = communication from program to user.
  • print vs println vs printf control formatting.
  • Escape sequences handle special characters and formatting.
  • Arithmetic expressions make output dynamic.
  • Menu.java demonstrates real-world application of expressions + output.

Output Methods

Method What it does Example Prints
print Prints and stays on the same line System.out.print("Hi "); Hi
println Prints, then moves to a new line System.out.println("Hi"); Hi, then a new line
printf Prints using a format pattern (not on the AP exam) System.out.printf("%.2f", 3.14159); 3.14

Escape Sequences

Sequence Meaning Example Prints
\" Double quote "She said \"hi\"" She said "hi"
\\ Backslash "C:\\Users" C:\Users
\n New line "A\nB" A and B on two lines
\t Tab (not on the AP exam) "A\tB" A and B with a tab between

Operator Precedence

Order Operators Example Result
1st ( ) (2 + 3) * 4 20
2nd *, /, %, left to right 2 + 3 * 4 14
3rd +, -, left to right 10 - 4 - 3 3

Predicting Output

  • Both values are int → the result is an int, decimals dropped
  • At least one double → the result is a double
  • A String comes first with + → everything after it is joined as text, unless it is in parentheses
  • print → the next output stays on the same line; println → the next output starts a new line

2. LxD Cycle Process

Empathize: Math class says 7 / 3 is about 2.33, but Java prints 2, and “Result: “ + 5 + 3 prints Result: 53. In a seven-country study, many students could not predict what short pieces of code would print (Lister et al., 2004).

Define:

  • POV: CSA students need to predict exactly what a line of Java prints, because integer division, precedence, and string joining do not match the math they already know.
  • Learning Goal: Students will print output with print and println, use escape sequences in strings, and work out the value of arithmetic expressions.

Ideate:

  • HMW Question: How might we get students to commit to a prediction before they press run?
  • HMW Question: How might we show that the same printing skills are how they will debug the class project?
  • Activity: Predict the output of short programs, run them to check, fix a broken string, then grow Menu.java into a calculator menu.

Prototype:

  • A reference guide, runnable print and Menu.java examples, a formatting-tools practice runner, an MCQ knowledge check, a six-part homework with a game, and a grading rubric.
  • Students write a prediction before each run and revise it after seeing the real output or the compiler error.
  • Excellence means predicting the exact output, including integer division, precedence, and string joining, and improving the first attempt rather than only producing working code.

Test:

  • Ask peers in peer review to complete the practice without additional explanation.
  • Observe whether peers commit to a prediction before they press run, and whether they predict integer division and string joining correctly.
  • Compare your lesson with another that is posted.
  • Use the findings to revise any instruction or rubric criterion that did not guide students clearly.
  • On submission, collect evidence from runner output, MCQ results, game screenshots, AI grading and student explanations.
  • After teaching, grading and analysis, come back and revise lesson to complete teaching cycle for continuous improvement.

3. College Board Requirements

AP CSA Unit 1, Topic 1.3 Expressions and Output. Quoted from the course and exam description (College Board, 2025, pp. 33-34):

  • 1.3.A.1 “System.out.println moves the cursor to a new line after the information has been displayed, while System.out.print does not.”
  • 1.3.C.3 “When dividing numeric values that are both int values, the result is only the integer portion of the quotient.”
  • 1.3.C.5 “Multiplication, division, and remainder have precedence over addition and subtraction. Operators with the same precedence are evaluated from left to right.”

The Java language specification says the same thing in one line: “Integer division rounds toward 0” (Gosling et al., 2023, section 15.17.2).

Note for the exam: the AP course uses only three escape sequences, \", \\, and \n. printf and \t are useful in real code but are not tested.


4. Lesson Plan

Learning Objective: Generate output, use string literals and escape sequences, and work out the result of arithmetic expressions.

Success Criteria: You can predict what print and println show, fix strings that need escape sequences, and evaluate expressions that use integer division, %, precedence, and string joining.

Tech Talk (5 minutes)

print stays on the same line. println moves to the next line.

Two int values always give an int, so division throws away the decimal part. One double changes that.

Code Runner Challenge

Predict how many lines this prints, then run it

View IPYNB Source
System.out.println(7 / 3);       // 2
System.out.println(7.0 / 3);     // 2.3333333333333335
System.out.println(7 % 3);       // 1  (remainder)
System.out.println(2 + 3 * 4);   // 14 (* before +)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

+ joins strings, and Java works left to right:

Code Runner Challenge

Change the simulated choice, then run it

View IPYNB Source
System.out.println("Result: " + 5 + 3);     // Result: 53
System.out.println("Result: " + (5 + 3));   // Result: 8
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Dividing an int by 0 does not fail at compile time. It throws an ArithmeticException while running.


5. Code Examples

A. Simple: print vs println


Code Runner Challenge

Replace the sample lines with your own, then run it

View IPYNB Source
// CODE_RUNNER: Predict how many lines this prints, then run it
public class PrintDemo {
    public static void main(String[] args) {
        // Example: println vs print
        System.out.print("Hello");
        System.out.print(" World");
        System.out.println("!"); // moves to new line
        System.out.println("Done");
    }
}

PrintDemo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

B. Complex: Menu.java

A menu uses literals, expressions, and output together. The runner has no keyboard, so this copy reads its choice from a String. Change "2\n" to another option and run it again.


Code Runner Challenge

Write your prediction first, then run it to check

View IPYNB Source
// CODE_RUNNER: Change the simulated choice, then run it
import java.util.Scanner;

public class MenuDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner("2\n");  // simulated keyboard input

        System.out.println("==== Main Menu ====");
        System.out.println("1. Start Game");
        System.out.println("2. Instructions");
        System.out.println("3. Exit");

        System.out.print("Choose an option: ");
        int choice = sc.nextInt();

        System.out.println("You selected option: " + choice);

        int optionCount = 3;
        System.out.println("There are " + optionCount + " total options.");
    }
}

MenuDemo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

6. Hacks & Practice Tasks

Prepare your submission IPYNB

  1. Create a new notebook in your portfolio homework area: _notebooks/homework.
  2. Add one raw cell at the top with the frontmatter:

Code Runner Challenge

Run it to see the compiler error, then fix the string and run it again

View IPYNB Source
---
layout: post
codemirror: true
title: Expressions and Output HW
categories: [Java]
lesson_language: Java
lesson_topic: Expressions-and-Output HW
lesson_part: interactive
lesson_type: lesson
permalink: /csa/unit_01/1_3-hw
author: yourGithubID
---
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...
  1. Add code cells for the Popcorn Hack and the Homework Hack. Make sure every cell runs with visible output.
  2. Submit the link to your published page at the bottom of this page, and paste this in the description box:

Code Runner Challenge

Fill in the blanks, then run it

View IPYNB Source
Lesson: CSA 1.3 Expressions and Output
MCQ 1.3: <paste the copied result line, such as 5/6 | answers: B,C,A,D>
Popcorn: six formatting lines with a comment on each, runs and prints (yes/no)
Popcorn: Menu.java tools named in a comment = <short summary>
Part 1 prediction: <what the three prints show>
Part 2 fixed line: <your corrected string>
Part 3: Settings added, optionCount = <value>
Part 4 printf output: <what it prints>
Part 5 calculator menu runs and prints the right result (yes/no)
Part 6: game screenshot sent to the 1.3 form (yes/no)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Submission Safety Rules (Read First)

  • One class per cell, ending with ClassName.main(null);.
  • Label the homework parts 1 through 6.
  • Run each Java cell and leave the output showing.
  • Include your MCQ score.
  • Use ## headings or smaller.

Popcorn Hack (In-Class)

2-minute challenge: from memory, write one line for each formatting job, then run the cell.

  1. Print two words that stay on the same line
  2. End a line so the next output starts below it
  3. Put a line break inside one string
  4. Put quotation marks inside a string
  5. Print a backslash
  6. Print a decimal with exactly 2 places
  7. In a comment, name the formatting tools Menu.java uses and how they make its output cleaner

Add a comment on each line saying what the tool does. Replace the sample lines with your own.

// CODE_RUNNER: Replace the sample lines with your own, then run it
// Practice #1 - Try it yourself first!
public class FormattingTools {
    public static void main(String[] args) {
        // Try writing your own lines here first!

        // Sample answer:
        System.out.print("Hello ");                        // print: stays on the same line
        System.out.println("World");                       // println: moves to a new line after
        System.out.println("Line one\nLine two");          // \n: new line inside a string
        System.out.println("She said \"Java is fun\"");    // \": quote inside a string
        System.out.println("Folder: C:\\Games");            // \\: backslash inside a string
        System.out.printf("Price: $%.2f\n", 4.5);          // printf: exactly 2 decimal places

        // Menu.java: println puts each option on its own line, print keeps the answer on the
        // same line as "Choose an option: ", and + joins the numbers into the sentences.
    }
}

FormattingTools.main(null);

MCQ Check

4 questions, one at a time. Answer, check, then go to the next one. At the end, copy the score line into your submission notes.

Homework Hack

Do all six parts.

Part 1: Predict. What does this print? Write your prediction, then run it.

// CODE_RUNNER: Write your prediction first, then run it to check
public class PredictOutput {
    public static void main(String[] args) {
        System.out.print("AP ");
        System.out.print("CSA ");
        System.out.print("Rocks!");
    }
}

PredictOutput.main(null);

Part 2: Fix the bug. This should print C:\Users\Student, but it will not compile. Fix it.

// CODE_RUNNER: Run it to see the compiler error, then fix the string and run it again
public class BackslashBug {
    public static void main(String[] args) {
        System.out.println("C:\Users\Student");
    }
}

BackslashBug.main(null);

Part 3: Menu Hack. Add a 4th option, Settings, to Menu.java and update optionCount.

Part 4: Challenge. Use printf to print pi with 2 decimals: System.out.printf("Pi = %.2f\n", Math.PI);

Part 5: Calculator menu. Grow Menu.java into a calculator with Add, Subtract, Multiply, and Divide. Skeleton below.

Part 6: Game. Play the game below, screenshot your score, and send it to the 1.3 form (it covers 1.3 and 1.4).

// CODE_RUNNER: Fill in the blanks, then run it
import java.util.Scanner;

public class CalculatorMenu {
    public static void main(String[] args) {
        // The runner has no keyboard, so the choice and numbers come from a String.
        Scanner sc = new Scanner("1\n10\n5\n");

        System.out.println("==== Calculator Menu ====");
        System.out.println("1. Add");
        // 1. Print the other three options

        System.out.print("Choose an option: ");
        int choice = sc.nextInt();
        System.out.print("Enter first number: ");
        int first = sc.nextInt();
        System.out.print("Enter second number: ");
        int second = sc.nextInt();

        // 2. Work out the result for the chosen option
        int result = 0;

        System.out.println("Result: " + result);
    }
}

CalculatorMenu.main(null);

1.3 and 1.4 Game

Grading Plan (1 Point Total)

Part Points What earns the points
Popcorn 0.2 Six formatting lines, each with a comment saying what the tool does, the Menu.java tools named, and the cell runs.
MCQ 0.2 5 or 6 correct. 0.15 for 3 or 4, 0.1 if every question was answered.
Homework Part 1 0.05 Predicts AP CSA Rocks! on one line.
Homework Part 2 0.05 Escapes the backslashes so the path prints.
Homework Part 3 0.05 Settings added and optionCount is 4.
Homework Part 4 0.05 printf prints pi with two decimals.
Homework Part 5 0.3 Four options, two numbers read, correct result printed.
Homework Part 6 0.1 Game score screenshot.
Total 1.0  

Quick Validation Checklist

  • Popcorn has all six formatting lines and names the Menu.java tools.
  • MCQ score in the notes.
  • \\ in the fixed Part 2 string.
  • Settings and optionCount = 4 in Part 3.
  • Part 5 output shows the menu and a Result: line.
  • Game screenshot.

7. Lesson Revisions

Revision Made: Lesson authors: what you changed because of it.


8. Feedback Evidence

Feedback Received: Lesson review of CSA 1.1 to 1.4, September 29, 2026.

  • Reference Guide (fixed): Only 5 bullets with no examples. It names escape sequences and printf but never shows them, and it refers to Menu.java before students have seen it.
  • Reference Guide (fixed): No table for escape sequences (\", \\, \n) or operator precedence, even though the MCQ and Homework Part 2 test both.
  • Grading Plan (open): The MCQ row gives full credit for “5 or 6 correct,” but the MCQ only has 4 questions, so full credit is impossible. The sample score line 5/6 has the same problem.
  • Game (open): Part 6 says the game “covers 1.3 and 1.4,” but the 1.4 Grading Plan does not count it.
  • Structure (fixed): The section order did not match the 1.2 model lesson. The Reference Guide came third, the College Board quotes sat inside the Lesson Plan, the Grading Plan was its own section, and Revisions and Feedback were combined.
  • Frontmatter (fixed): Missing keys that the 1.2 model has, including assignment_submission_type, assignment_creator_uids, and Group.

9. References

College Board. (2025). AP Computer Science A course and exam description [Effective fall 2025]. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description-effective-fall-2025.pdf

Gosling, J., Joy, B., Steele, G., Bracha, G., Buckley, A., Smith, D., & Bierman, G. (2023). The Java® language specification (Java SE 21 ed.). Oracle. https://docs.oracle.com/javase/specs/jls/se21/html/index.html

Lister, R., Adams, E. S., Fitzgerald, S., Fone, W., Hamer, J., Lindholm, M., McCartney, R., Moström, J. E., Sanders, K., Seppälä, O., Simon, B., & Thomas, L. (2004). A multi-national study of reading and tracing skills in novice programmers. In Working group reports from ITiCSE on Innovation and Technology in Computer Science Education (pp. 119–150). Association for Computing Machinery. https://doi.org/10.1145/1044550.1041673

past homework

Submit Assignment

Self-Assessment

Rate your work on this assignment, then add a short reflection. All 5 fields are required before you can submit.

Technical Excellence

Rate the technical quality of your work on this assignment — your use of tools, problem-solving, and technical growth.

1 Explore · 2 Understand · 3 Apply · 4 Analyze/Evaluate · 5 Create/Extend
Communication

Rate how clearly you communicated your work and process — explanations, documentation, and collaboration or help-seeking.

1 Beginning · 2 Developing · 3 Consistent · 4 Strong · 5 Model
Work Habits

Rate your work habits on this assignment — time management, persistence, responsibility, and follow-through.

1 Beginning · 2 Developing · 3 Consistent · 4 Strong · 5 Model
AI Orchestration

Rate how effectively you used AI tools to support your work — prompting, verifying, extending, or accelerating your development process.

1 Explore · 2 Understand · 3 Apply · 4 Analyze/Evaluate · 5 Create/Extend

This submits the code from this lesson's code runner(s) below as a Gist for automatic review. Save each runner with its 💾 button before submitting.

    Need to update a submission later? Open the submissions dashboard.