📜 WAYPOINT LESSON
Tracing execution
⭐ beginner⏳ 10 min read📍 Lesson 2 of 256
main runs top to bottom; print vs println; printing expressions vs text.
main runs top to bottom. Trace it like the exam asks you to:
public class Solution {
public static void main(String[] args) {
System.out.print("AB");
System.out.println("CD");
System.out.println("EF");
}
}
Output:
ABCDEF
EF
Why two lines, not three? print("AB") writes AB and stays on the same
line; println("CD") finishes that line. Trace rules:
- One statement at a time, in order.
printstays on the line;printlnends it.println()with no argument prints just a blank line.
You can also print computed values:
System.out.println(3 + 4); // 7
System.out.println("3 + 4"); // 3 + 4
Quotes make text; no quotes means Java evaluates the expression first.
⚡ Now practice
Ready to CodeFirst programsWrite, predict, and fix complete Java programs.
4 challenges · · ~35 min