Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Format Output with Formatter in Java
For Formatter, import the following package −
import java.util.Formatter;
Now create a Formatter object −
Formatter f1 = new Formatter();
Now, we will format the output with Formatter −
f1.format("Rank and Percentage of %s = %d %f", "John", 2, 98.5);
The following is an example −
Example
import java.util.Formatter;
public class Demo {
public static void main(String args[]) {
Formatter f1 = new Formatter();
Formatter f2 = new Formatter();
f1.format("Rank and Percentage of %s = %d %f", "John", 2, 98.5);
System.out.println(f1.toString());
f2.format("Rank and Percentage of %s %s = %d %f", "David", "Warner", 1, 80.8);
System.out.println(f2.toString());
}
}
Output
Rank and Percentage of John = 2 98.500000 Rank and Percentage of David Warner = 1 80.800000
Advertisements
