簡體   English   中英

的System.out.println();和System.err.println();可互換印刷

[英]System.out.println(); and System.err.println(); printing interchangeably

此代碼是程序的一部分。

System.out.print("Enter your deposit amount: ");
double deposit = scanner.nextDouble();
bankObj.deposit(deposit); //this method will print a syserr if the number entered is negative
if (deposit > 0) {
    System.out.println("Thank you for depositing the amount of "+deposit+" to account number "+bankObj.accountNum+".");
}
    System.out.println("Program exiting.");

輸出:

Enter your deposit amount: -2
//sometimes it will print.
Program exiting.
Account.deposit(...): cannot deposit negative amount. //This is from the deposit method
//or
Account.deposit(...): cannot deposit negative amount. //This is from the deposit method
Program exiting.

為什么會這樣? 我嘗試將它放在循環和語句之外(這可能是問題),但行為沒有改變。 我正在使用Eclipse。

這是兩個不同的輸出流,它們被調用的順序並不是唯一重要的。 他們可能會在不同的時間向控制台刷新內容。

編輯:經過多一點挖掘后, 這個答案表明它可能是一個(未解決的) 日食錯誤 它已經開放了10年,不會很快得到你的希望。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM