PrintWriter printf Example
PrintWriter class printf example. This example shows you how to use printf method.
PrintWriter class printf example. public PrintWriter printf(String format, Object... args) A convenience method to write a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer.
Here is the code
/**
* @ # Printf.java
* A class reprsenting use to printf method
* of PrintWriter class in java.io package
* version 10 June 2008
* author Rose India
*/
import java.io.*;
public class Printf2 {
public static void main(String args[]) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
int i = 0;
printWriter.printf("i = %d",i);
System.out.println(stringWriter.getBuffer());
}
} |
|