本文介紹了使用 printf 和 format 進(jìn)行格式化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
在下面的程序中
class ZiggyTest2 {
public static void main(String[] args){
double x = 123.456;
char c = 65;
int i = 65;
System.out.printf("%s",x);
System.out.printf("%b",x);
System.out.printf("%c",c);
System.out.printf("%5.0f",x);
System.out.printf("%d",i);
}
}
輸出是
123.456trueA 12365
誰能解釋一下雙精度值(即123.456
)如何轉(zhuǎn)換為布爾值(即true
)
Can someone please explain how a double value (i.e. 123.456
) is converted to a boolean (ie. true
)
我問的原因是因為我知道 java 不允許將數(shù)字用于布爾值.例如,Java 中不允許以下內(nèi)容
The reason I ask is because I know java does not allow numbers to be used for boolean values. For example, the following is not allowed in Java
if (5) {
//do something
}
謝謝
推薦答案
for "%b" : 如果參數(shù) arg 為 null,則結(jié)果為 "false".如果 arg 是布爾值或布爾值,則結(jié)果是 String.valueOf() 返回的字符串.否則,結(jié)果為真".
for "%b" : If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(). Otherwise, the result is "true".
參考
這篇關(guān)于使用 printf 和 format 進(jìn)行格式化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!