Java.io.PrintWriter.print( double d) 方法
描述
java.io.PrintWriter.print() 方法打印一个双精度浮点数。 String.valueOf(double) 生成的字符串按照平台默认的字符编码转换为字节,这些字节的写入方式与 write(int) 方法完全相同。
声明
以下是 java.io.PrintWriter.print() 方法的声明。
public void print(double d)
参数
d − 要打印的 double。
返回值
此方法不返回值。
异常
NA
示例
下面的例子展示了 java.io.PrintWriter.print() 方法的使用。
package com.tutorialspoint;
import java.io.*;
public class PrintWriterDemo {
public static void main(String[] args) {
double d = 1234.567;
// create a new writer
PrintWriter pw = new PrintWriter(System.out);
// print double
pw.print(d);
// change the line
pw.println();
// print another double
pw.print(987.654);
// flush the writer
pw.flush();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
1234.567 987.654

