printWriter print3 Example
printWriter class print example. This example shows you how to use print method.
PrintWriter class print example.method generates floating numbers called decimal numbers in to the abstract pathname file and not on program output console.method throws null pointer exception if null is passed.
Here is the code:-
/**
* @Program uses print method to print floating type numbers
* or decimal numbers in the file invoked by File class object;
* Print3.java
* Author:-RoseIndia Team
* Date:-6-july-2008
*/
import java.io.*;
public class Print3 {
public static void main(String args[]) throws IOException {
File file = new File("c:\bunty.txt");
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
file)));
out.print(1.0D);
out.print(0.0f);
out.print(0.006f);
out.print(0.00006);
out.flush();
}
} |
program Output:-
Output is generated in the file and not on console
Output in scientific notations
1.00.00.00606.0E-5 |
|