![](/img/trans.png)
[英]System.out.println and System.err.println out of order
[英]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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.