Wednesday, January 1, 2025
HomeTechHow to Print in Java

How to Print in Java

Java provides several methods to display output:

1. System.out.print()

Prints text without moving to the next line.

java
System.out.print("Hello, ");
System.out.print("World!");

Output: Hello, World!

2. System.out.println()

Prints text and moves to the next line.

java
System.out.println("Hello, World!");
System.out.println("Java is fun!");

Output:

kotlin
Hello, World!
Java is fun!

3. System.out.printf()

Formats and prints output using placeholders.

java
System.out.printf("Name: %s, Age: %d\n", "Alice", 25);

Output: Name: Alice, Age: 25

4. Printing Variables

java
int number = 42;
System.out.println("Number: " + number);

Output: Number: 42


Key Notes:

  • print(): No newline.
  • println(): Adds a newline.
  • printf(): For formatted output.
  • Escape characters like \n (new line) and \t (tab) enhance formatting.
See also  What is Bit Masking in C?

This is how you print effectively in Java!

RELATED ARTICLES

Leave a Reply

- Advertisment -

Most Popular

Who is Sharky?

Celebrities Born in 1973

Who Is Brenda Lee?

Who Is Joy Behar?

Recent Comments