OJCP(SCJP)題庫下載題庫

上一題
第9題 Given: 11. String[] elements = {"for", "tea", "too"}; 12. String first = (elements.length>0) ? elements[0] : null; What is the result?
(A) Compilation fails.
(B) An exception is thrown at runtime.
(C) The variable first is set to null.
(D) The variable first is set to elements[0]


答案:登入後觀看
難度: 適中
最佳解!
bill76061340 幼兒園下 (2017/05/10)
Given:11.    String[] ☆☆☆☆☆☆☆ ...


(內容隱藏中)
查看隱藏文字
2F
鄒錦翔 幼兒園下 (2017/07/06)

三元運算子

(條件式) ? "符合條件的答案" : " 不符合條件的答案"

就像是if else


String[] elements = {"for", "tea", "too"};

String first = (elements.length>0) ? elements[0] : null; 


如果陣列的長度大於0的就讓字串first =elements[0],

而不滿足這個條件的就讓first=null


第9題 Given: 11. String[] elements = {"f..-阿摩線上測驗