下列Java語言程式片段中,那些指令敘述是合法的?
- (A) String s = "hello"; boolean b[] = {true,false}; Boolean bw = new Boolean(b[0]); s = s + bw; 正確答案
- (B) char s[] = {'h', 'e','l','o','o'}; int i = 15; s = s + i;
- (C) float f = 5; char c = 20; f = f + c; 正確答案
- (D) double d = -10.5 d = d % 2 正確答案
官方答案:(A)String s = "hello"; boolean b[] = {true,false}; Boolean bw = new Boolean(b[0]); s = s + bw;、(C)float f = 5; char c = 20; f = f + c;、(D)double d = -10.5 d = d % 2
詳解
字串可與物件相加、float加char成立、double可取餘數;字元陣列不能直接與int相加。
同章其他題目:Java
題目與答案照電腦軟體設計(JAVA)乙級官方公開題庫(114.09.01 版)收錄;詳解是我寫的整理,正式內容以主管機關公告為準。