- 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
Left justify output in Java
Including a minus sign after the %, makes it left justified.
Note − By default, output is right justified
Firstly, create a formatter object −
Formatter f = new Formatter();
Now, use the format() method to left justify output −
f.format("|%-15.5f|", 299.675796)
The following is an example −
Example
import java.util.*; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); // left justify f = new Formatter(); System.out.println(f.format("|%-15.5f|", 299.675796)); } }
Output
|299.67580 |
Advertisements