IO.print()
Prints a value to the console without ending the line.
Available since: Java 25
Syntax
static void print(Object obj)Parameters
| Parameter | Type | Description |
|---|---|---|
| obj | Object | What to print. |
Return value
voidNothing.
Examples
Printing on one line in a loop:
void main() {
for (int i = 1; i <= 5; i++) {
IO.print(i + " ");
}
IO.println();
IO.print("no newline at the end");
}Output:
1 2 3 4 5
no newline at the endNotes
You can add the line break yourself, IO.print("text\n"), but IO.println() is usually clearer. Unlike printf(), there are no %s placeholders here — build the string with "...".formatted(...) to format it.
See also
- IO.println() — Prints a value to the console and ends the line.
- IO.readln() — Prints a prompt and reads a line typed by the user.
- System.out.printf() — Prints a string built from a template with %s, %d, %.2f placeholders.
In the tutorial
- Your first program — The parts of a Java program: the main method, statements, output with IO.println, comments and the classic form with public class Main.