1.3

Expressions and Output

Use System.out.print/println with arithmetic expressions, string literals, and escape sequences to produce formatted program output.

1525% of exam
Understand It
Ace It
Context

What this topic is and why it exists

Imagine you're a theater director controlling a giant marquee sign.
You get to decide exactly what lights up and whether the next message appears on the same line or drops down to a new one.
That's essentially what `System.out.print` and `System.out.println` do in Java.
The first keeps the cursor right where it is after displaying your message, so the next thing printed sits snugly beside it.
The second does the same job but then hits "enter," moving the cursor to a fresh line.
Simple as that — one stays put, one moves down.
Now, what can you actually display?
Numbers, math results, and text.
Java lets you build arithmetic expressions using `+`, `-`, `*`, `/`, and `%` (remainder).
Here's the critical trick: if every number involved is an `int`, the result is an `int` — so `7 / 2` gives you `3`, not `3.5`.
But the moment a `double` sneaks into the mix, the whole result becomes a `double`.
For text, you wrap characters in double quotes to create a string literal, and when you need special characters — like a quote inside a quote, a backslash, or a new line — you use escape sequences like `\"`, `\\`, and `\n`.
Master these small tools and you control exactly what your program says and how it says it.
1 / 9