[單項選擇題] 下面的哪些程序段可能導致錯誤 ( ) Ⅰ: String s = "Gone with the wind";String t = "good
2021-07-20
[單項選擇題] 下面的哪些程序段可能導致錯誤 ( ) Ⅰ: String s = "Gone with the wind";String t = "good ";String k = s + t; Ⅱ: String s = "Gone with the wind";String t;t = s[3] + "one"; Ⅲ: String s = "Gone with the wind";String standard = s.toUpperCase(); Ⅳ: String s = "home directory";String t = s-"directory":
A.Ⅱ、Ⅲ
B.Ⅱ、Ⅳ
C.Ⅰ、Ⅳ
D.Ⅲ、Ⅳ
正確答案:B
參考解析:本題是考杳對String操作符的理解和應用。Ⅰ段中,String類型可以直接使用+進行連接運算:Ⅱ段中,String是一種Object,而不是簡單的字符數組,不能使用下標運算符取其值的某個元素,錯誤;Ⅲ段中, toUppelCase0方法是String對象的一個方法,作用是將字符串的內容全部轉換為大寫并返回轉換后的結果(String類型);IV段中,String類型不能進行減(—)運算,錯誤。
詞條內容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學等領域),建議您咨詢相關領域專業(yè)人士。