3 回答
TA贡献2036条经验 获得超8个赞
貌似跟缓存没啥关系,println的源码是这样的:
public void println(String x) {
synchronized (this) {
print(x);
newLine();
}
}
然后是printf的源码:
public PrintStream printf(String format, Object ... args) {
return format(format, args);
}
在format里面就是单纯的格式化操作没啥了
public PrintStream format(String format, Object ... args) {
try {
synchronized (this) {
ensureOpen();
if ((formatter == null)
|| (formatter.locale() != Locale.getDefault()))
formatter = new Formatter((Appendable) this);
formatter.format(Locale.getDefault(), format, args);
}
} catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
} catch (IOException x) {
trouble = true;
}
return this;
}
至于你的那个问题你可以把代码里打印输出的那一句改为:
System.out.printf("Number is Prime: %d", number);
System.out.print("\r");
就可以了
TA贡献1906条经验 获得超3个赞
Integer number = 55;
System.out.printf("Number " + number + " is Prime\n");
System.out.printf("Number %s is Prime", number);
换行是一个区别,但是最主要的区别是printf
可以格式化表达式,具体格式语法可参考java.util.Formatter
添加回答
举报