我正在尝试这个教科书示例,我检查了一下,这正是书中的内容:-
public class StringBuilderConstructors
{
public static void main(String[] args)
{
Object objectRef = "hello";
String string = "goodbye";
char[] charArray = {'a','b','c','d','e','f'};
boolean booleanValue = true;
char characterValue = 'Z';
int integerValue = 7;
long longValue = 10000000000L;
float floatValue = 2.5f;
double doubleValue = 33.333;
StringBuilder lastBuffer = new StringBuilder("last buffer");
StringBuilder buffer = new StringBuilder();
buffer.append(objectRef)
.append(System.getProperty("line.seperator"))
.append(string)
.append(System.getProperty("line.seperator"))
.append(charArray)
.append(System.getProperty("line.seperator"))
.append(booleanValue)
.append(System.getProperty("line.seperator"))
.append(characterValue)
.append(System.getProperty("line.seperator"))
.append(integerValue)
.append(System.getProperty("line.seperator"))
.append(longValue)
.append(System.getProperty("line.seperator"))
.append(floatValue)
.append(System.getProperty("line.seperator"))
.append(doubleValue)
.append(System.getProperty("line.seperator"))
.append(lastBuffer);
System.out.printf("buffer contains%n%s %n", buffer.toString());
}
}
但它给我的结果是完全错误的。
缓冲区包含 hellonullgoodbyenullabcdefnulltruenullZnull7null10000000000null2.5null33.333nulllast 缓冲区
这整件事不应该在一条线上。