java · level 1 · unit 1 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Lines run in order, one after another.
A program can have lots of lines. Java runs them in order, top to bottom, like ticking off a shopping list. Everything your program shows on the screen is called its .
An empty System.out.println() has nothing to show, so you get a blank line. It is handy for spacing things out.
println moves to a new line after showing its text. Its cousin , with no ln, stays on the same line, so the next text carries straight on.
public class Main {
public static void main(String[] args) {
System.out.println("Ready");
System.out.println("Steady");
System.out.println();
System.out.print("Go, ");
System.out.println("go, go!");
}
} The ln in println is short for line, so it means print a line.
guess first
How will this look on the screen?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
public class Main {
public static void main(String[] args) {
System.out.print("Fish ");
System.out.print("and ");
System.out.println("chips");
}
}
your turn
Your turn. Write a knock knock joke.
Type who is at the door on lines 5 and 6, the same both times. Put your punchline on line 8, then press run and enjoy your output.
output
press run to see what happens
fix it
The cheer is all squashed together. Can you fix it?
output
press run to see what happens
- Run it and look at the output. Every word lands on the same line.
printstays on the line. Which command moves to a new line afterwards?- Change each
printtoprintln, then press run.
nailed it
you made the computer tell a joke. :D
- Lines run in order, from top to bottom.
- An empty
println()makes a blank line. printstays on the line.printlnmoves to a new one.
new words in your collection
- output
This lesson isn’t saved. A free account remembers every lesson you finish.