我對Java很新穎。Java'System.err.format''''n'後跟'System.out.println',println打印在中間
我使用的是Ubuntu 16.04,JDK 8u101,Netbeans8.1。
當試圖驗證碼:
public static void main(String[] args) {
System.err.format("1st Line %nPrints At 3rd Line,Shouldn't this be In 2nd Line ");
System.out.println("Shouldn't this be the third line,prints at 2nd line");
}
輸出是:
This Prints At 1st Line
Shouldn't this be the third line, but prints at 2nd line
This Prints At 3rd Line, Shouldn't this be In 2nd Line
爲什麼 「System.out.println
」 打印在中間? 不應該最後打印。
我 「%n
」 試圖在最後& System.err.flush()
這樣的:
System.err.format("1st Line %nPrints At 3rd Line,Shouldn't this be In 2nd Line%n");
System.err.flush();
System.out.println("Shouldn't this be the third line,prints at 2nd line");
還是相同的輸出。
您正在打印到兩個不同的流,它們只在行的末尾刷新,但System.err在第二行末尾沒有刷新。 –