- 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
Set a Minimum Field Width in Java
The minimum field width specifier is what you include between % and the format conversion code.
To include a 0 before the field width specifier, pad with 0's. An integer between the % sign and the format conversion code acts as a minimum field width specifier.
Let us see an example −
Example
import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); System.out.println(f.format("%08d", 697)); f = new Formatter(); System.out.println(f.format("%10d", 9878)); f = new Formatter(); System.out.println(f.format("%06d", 697)); } }
Output
00000697 9878 000697
Advertisements