Java的输出print()/println()/printf()

本文介绍了Java中用于输出的三种方法:print()、println()和printf()。print()方法用于输出内容但不换行,println()方法在输出后会自动换行,而printf()方法则允许自定义格式进行内容输出。在尝试输出double类型数据时需要注意调用正确的方法,避免出现类型匹配错误。
摘要由CSDN通过智能技术生成

java输出包含小数位的double型数据

System.out.println("%.4f",d);

报错:The method println(double) in the type PrintStream is not applicable for the arguments (String, double)

原因:Java的输出中System是java.lang里面的一个类

public final class System

out是System里面的一个静态数据成员 ,out的类型是PrintStream类型

public final static PrintStream out = null;
java.io.PrintStream 

println()是PrintStream的方法

public class PrintStream extends FilterOutputStream
    implements Appendable, Closeable
{
    ........
    ........
    ........
    /* Methods that do not terminate lines */    
    /**
     * Prints an object.  The string produce
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值