多选题 What is the value of the variable sum at the end of this code segment? int[][] square=new int[3][3]; for(int i=0;i<3;i++) { square[i][i]=5; } int sum=0; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { sum+=square [i][j]; } } A. 0 B. 5 C. 10 D. 15 E. 20 F. 25 G. 30 H. 35 I. 40 J. 45 K. 50 L. It will generate a compiler error.
【正确答案】 D
【答案解析】所有基本数据类型的数组元素的初始值都是0。然后第一个for循环设置square[0][0]、square[1][1]和square[2][2]为5。在第二个for循环中,对所有数组元素求和,结果最后sum变量的值为15。A、B、C、E、F、G、H、I、J、K和L不正确。