Java Output Numbers

Java Output Numbers

In Java, you can print numbers the same way you print text — using System.out.print(), System.out.println(), or System.out.printf().


Printing Integer Numbers


Output:

100
25

Printing Variables as Numbers


Output:

21

Printing Multiple Numbers Together


Output:

30

🧮 Printing Numbers with Text


Output:

Marks: 90

🔢 Printing Floating Numbers


Output:

99.99

📌 Using printf() for Format


 

Output:

Number: 50, Pi: 3.14

Format Specifiers:

Specifier Meaning
%d Integer
%f Floating-point
%.2f Floating with 2 decimals

📍 Printing Numbers Using Escape Sequences


Output:

10
20
30

➕ Concatenating Numbers with Strings


 

Parentheses ensure addition happens before concatenation.

Output:

Sum: 12

🧠 Example Program


 

Output:

10
Salary: 45000.75
Formatted Salary: 45000.75

⭐ Summary

Method Used For
println() Print numbers normally
print() Print without new line
printf() Print with formatting
Concatenation (+) Print numbers with text

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *