- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Different ways to format long with Java System.out.format
The System.out.format is used in Java to format output. Here, let’s say the following is our long.
long val = 787890;
To format, we have considered the following that justifies the output.
System.out.format("%d%n", val); System.out.format("%9d%n", val); System.out.format("%+9d%n", val); System.out.format("%08d%n", val); System.out.format("%,9d%n", val);
The following is the complete example that displays the difference in output as well.
Example
import java.util.Locale; public class Demo { public static void main(String []args) { long val = 787890; System.out.format("%d%n", val); System.out.format("%9d%n", val); System.out.format("%+9d%n", val); System.out.format("%08d%n", val); System.out.format("%,9d%n", val); } }
Here is the output. You can easily notice the differences in format.
Output
787890 787890 +787890 00787890 787,890
- Related Articles
- Java Program to format date with System.out.format
- Long style format for Date with Java MessageFormat class
- Different ways to concatenate Strings in Java
- Different ways to create Objects in Java
- 5 different ways to create objects in Java
- Different ways to overload a method in Java
- Different ways to print exception messages in Java
- Different ways to traverse an Array in Java?
- Different ways to create an object in java?
- Java Program to Display time in different country’s format
- Different ways for Integer to String conversion in Java
- Different ways to initialize list with alphabets in python
- Java Program to Display Dates of Calendar Year in Different Format
- Java Program to format date with SimpleDateFormat
- Java Program to format date with DateFormat.FULL

Advertisements