Java Output Numbers

Java Tutorial

Java Output Numbers – Complete Guide

In Java Output Numbers are printed using System.out.print() or System.out.println().


 1. Print a Number (Basic)

Output:

10

 2. Print Integer Variables

Output:

25

 3. Print Multiple Numbers


 

Output:

10
20

 4. Print Numbers on Same Line


 

Output:

1020

 No space or new line automatically


 5. Print Numbers with Text

Output:

Age is 21

 6. Print Result of Calculation


 

Output:

15

 7. Print Decimal Numbers

Output:

99.99

 8. Print Using Formatting (printf)


 

Output:

x = 10, y = 12.35

9. Print Numbers in Loop

Output:

1
2
3
4
5

 10. Common Beginner Mistakes

  •  Forgetting main() method
  •  Missing semicolon ;
  •  Using print instead of System.out.print

 11. Interview Questions (Must Know)

Q1: Difference between print() and println()?
println() moves to new line
print() does not

Q2: How to print formatted numbers in Java?
System.out.printf()


 Quick Cheat Sheet


 

You may also like...