我知道这是一个非常简单的问题,但我想知道布尔类型的字符串格式。例如,下面显示了用于整数,字符串和浮点的字符串格式。布尔值
true
/
false
?的适当格式是什么?
System.out.printf("The value of the float " +
"variable is %f, while " +
"the value of the " +
"integer variable is %d, " +
"and the string is %s",
floatVar, intVar, stringVar);
''b'或'b'一般如果参数arg为null,则结果为“ false”。如果ARG是布尔或布尔值,则结果是字符串返回的字符串。Valueof(arg)。否则,结果是“真”。 Java Docs:Http://docs.oracle.com/javase/7/docs/api/java/java/java/util/formatter.html#syntax
System.out.printf("boolean variable is %b",boolVar);
更多方法是-
String output = String.format("boolean variable is %b",true);
System.out.print(output);
布尔的占位符为
%b
System.out是一个PrintStream,并且用于PrintStream.printf的文档链接到Format流语法,其中包含所有转换的表。该表中的第一个条目:
'b'
,'B'
-如果参数arg是null
,则结果为"false"
。如果arg是boolean
或Boolean
,则结果是由String.valueOf(arg)
返回的字符串。否则,结果是"true"
。
float floatVar=1.0f;
int intVar=1;
String stringVar="hi";
boolean boolVar=false;
System.out.printf("The value of the float " +
"variable is %f, while " +
"the value of the " +
"boolean variable is %b, " +
"and the string is %s",
floatVar, boolVar, stringVar);
%b
你在看