print、printf、println在Java中的使用

2 篇文章 0 订阅

print、printf、println在Java中的使用

一、println

在JAVA中常常使用System.out.pirntf();的输出格式。

比如最常见的 hello world

public class PrintTest{
	public static void main(Stirng[] args){
		System.out.println("hello world");
        System.out.println("hello world");
        System.out.println("hello world");	
	}
}

输出结果

hello world
hello world
hello world

即println在JAVA中具有换行输出的功能


二、print

在JAVA中常常使用System.out.pirnt();的输出格式。
public class PrintTest{
	public static void main(Stirng[] args){
		System.out.print("hello world");
        System.out.print("hello world");
        System.out.print("hello world");	
	}
}

输出结果

hello world hello world hello world

所以说print在JAVA中只是一般输出


三、printf

在JAVA中常常使用System.out.printf();的格式
public class PrintTest{
	public static void main(Stirng[] args){
		float a = 11.1432;
        System.out.printf("%.2f",a);
	}
}

输出结果

10.14

printf常常使用于格式转化

四、总结:

1. print为一般输出,同样不能保留精度格式转化,也不能换行输出
2.printf常用于格式转换,但需要注意不是换行输出,只用于精度转换
3.println为换行输出,不能用于格式转换

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

star__king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值