0
0
Javaprogramming~10 mins

Output using System.out.print in Java - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Output using System.out.print
Start Program
Call System.out.print
Print text to console
Cursor stays on same line
Program continues or ends
The program starts, calls System.out.print to show text on the screen, and the cursor stays on the same line for more output.
Execution Sample
Java
public class Main {
  public static void main(String[] args) {
    System.out.print("Hello ");
    System.out.print("World!");
  }
}
This code prints "Hello " and then "World!" on the same line without moving to a new line.
Execution Table
StepCode LineActionOutput on ConsoleCursor Position
1System.out.print("Hello ");Prints 'Hello 'Hello After 'Hello ' on same line
2System.out.print("World!");Prints 'World!'Hello World!After 'World!' on same line
3End of main methodProgram endsHello World!Cursor stays after last character
💡 Program ends after printing both strings without moving to a new line.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
Output String"""Hello ""Hello World!""Hello World!"
Key Moments - 2 Insights
Why does the output stay on the same line after System.out.print?
System.out.print prints text but does NOT add a new line, so the cursor stays right after the printed text (see execution_table steps 1 and 2).
What happens if we want to move to a new line after printing?
You need to use System.out.println instead, which adds a new line after printing (not shown here, but different from System.out.print).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is printed after step 1?
A"Hello "
B"World!"
C"Hello World!"
DNo output yet
💡 Hint
Check the 'Output on Console' column at step 1 in the execution_table.
At which step does the console show the full text "Hello World!"?
AStep 1
BStep 2
CStep 3
DNever
💡 Hint
Look at the 'Output on Console' column for each step in the execution_table.
If we replace System.out.print with System.out.println in step 1, what changes in the output?
AOutput stays the same on one line
BCursor moves to next line after printing 'Hello '
CProgram prints nothing
DProgram crashes
💡 Hint
Recall that System.out.println adds a new line after printing, unlike System.out.print (see key_moments).
Concept Snapshot
System.out.print("text");
- Prints text to console
- Cursor stays on same line
- Use for continuous output
- Does NOT add a new line
- To add new line, use System.out.println
Full Transcript
This example shows how System.out.print works in Java. The program prints "Hello " first, then "World!" right after it on the same line. The cursor does not move to a new line after printing. This is different from System.out.println, which moves the cursor to the next line after printing. The execution table traces each print call and shows the output growing step by step. Variables track the output string as it builds. Key moments explain why the cursor stays on the same line and how to print with a new line if needed. The quiz tests understanding of output after each step and the difference between print and println.