下面的那些程序片段可能导致错误()
a。String s = "Gone with the Wind"; String standard = s.toUpperCase();
b. String s = "Gone with the wind"; String t; t = s[3]+"one" ;
c. String s = "home directory"; String t = s-"directory";
d. String s = "Gone with the wind"; String t = "good"; String k = s + t ;
a。String s = "Gone with the Wind"; String standard = s.toUpperCase();
b. String s = "Gone with the wind"; String t; t = s[3]+"one" ;
c. String s = "home directory"; String t = s-"directory";
d. String s = "Gone with the wind"; String t = "good"; String k = s + t ;
b,没有初始化String对象,空指针错
c."-”错,没这种运算
d.之所没错,经过“+”,引用k指向了一个新的字符串,并不是真正修改了原字符串
要想真改,用StringBuffer
b 如果是 字符不超过三个则a[3] 是错误的
c 字符串中没有 - 这个写法