Home › Java Tutorial › Java output
Java output
Print with println, print and printf.
System.out.println prints and moves to a new line, System.out.print stays on the same line, and System.out.printf formats values: %d int, %.2f decimals, %s text, %n new line.
Example code
public class Main {
public static void main(String[] args) {
System.out.println("Line 1");
System.out.print("No newline, ");
System.out.print("same line\n");
System.out.printf("Age %d, pi %.2f, name %s%n", 20, 3.14159, "Ada");
}
}