Java Output Print Statements

Java Output Print Statements
In Java Output Print Statements is displayed on the screen using the System.out object.
There are mainly three printing methods:
| Method | Description |
|---|---|
print() | Prints text but does NOT move to a new line |
println() | Prints text and moves to a new line |
printf() | Used for formatted output |
System.out.print()
This prints output on the same line.
Output:
System.out.println()
This prints output and automatically moves to the next line.
Output:
Difference Between print and println
| Code | Output |
|---|---|
System.out.print("Hello"); System.out.print("Java"); | HelloJava |
System.out.println("Hello"); System.out.println("Java"); | Hello Java |
System.out.printf() (Formatted Output)
Useful for formatted printing like numbers, decimals, strings.
Output:
Format Specifiers:
| Format | Meaning |
|---|---|
%d | Integer |
%f | Floating number |
%.2f | Floating with 2 decimal places |
%s | String |
%c | Character |
Example:
Output:
Printing Multiple Values With Concatenation
Use + operator to combine text and variables.
Escape Characters in Output
| Escape | Meaning | Example Output |
|---|---|---|
\n | New line | Moves text to next line |
\t | Tab space | Adds extra spacing |
\" | Prints quotes | "Hello" |
\\ | Prints backslash | \ |
Example:
Output:
Example Program
Summary
| Method | Moves to new line? | Use case |
|---|---|---|
print() | No | Print continuously |
println() | Yes | Print line-by-line |
printf() | No (unless you add \n) | Formatted output |
