4 回答

TA貢獻1802條經驗 獲得超4個贊
嘗試這個。
在 System.out.println() 方法內部,每個變量都將其稱為s string representation to print. But if it原始數據類型 -> 然后我們需要將其稱為s to string method to print it精確值。
您可以使用 .toString() 方法連接
public static void main(String[] args) {
Boolean isTrue = false;
Double money = 99999.99;
System.out.println(money + isTrue.toString());
}

TA貢獻1874條經驗 獲得超12個贊
試試這個方法:
System.out.println(money + " " + (isTrue ? "True" : "False"));
或者簡單地:
System.out.println(money + " " + isTrue);

TA貢獻1906條經驗 獲得超3個贊
這是因為 println 會自動將其輸入轉換為字符串進行打印。在進行類型轉換之前,“()”內部的任何邏輯都將首先執行。由于您有兩種不同的值類型,通常無法將它們加在一起,因此此邏輯失敗。您需要將所有值轉換為字符串才能使用“+”作為連接。
或者,考慮使用StringBuilder或StringFormat

TA貢獻1776條經驗 獲得超12個贊
用字符串連接它們:
Boolean isTrue = false;
Double money = 99999.99;
System.out.println(money + " " + isTrue);
添加回答
舉報