在Java中使用%n或\ n格式化字符串 [英] Using %n or \n in Java to format String

查看:1113
本文介绍了在Java中使用%n或\ n格式化字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中%n和\ n有什么区别?

What is the difference between %n and \n in Java?

例如,

System.out.printf("Hello, world! %n");

System.out.printf("Hello, world! \n");

两者对我来说都返回相同的输出.

Both return the same output for me.

推荐答案

据我所知,不同之处在于%n将始终根据平台输出正确的换行符,而\n则不会.

Well, as far as i know the difference is that %n will always output the correct line break depending on the platform while \n won't.

这篇关于在Java中使用%n或\ n格式化字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆