[英]how to print "hello world" without MAIN method and also without using STATIC and FINAL key word in java
[英]How to print Hello World without semicolon in Java?
有人可以向我解釋為什么 printf 有效但 println 無效嗎?
if (System.out.printf("Hello World") == null);
if (System.out.println("Hello World") == null);
println
有一個void
返回類型,所以你不能將它與null
(或其他任何東西)進行比較。
public void println(String x) {
synchronized (this) {
print(x);
newLine();
}
}
printf
返回一個PrintStream
實例,允許您將其與null
進行比較(盡管我認為您沒有理由這樣做,因為它永遠不會返回null
)。
public PrintStream printf(String format, Object ... args) {
return format(format, args);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.