AP计算机教程6-8:简单多选题
0:00
Which index is the last element in an array called nums
at?
因为数组的索引从
0
开始,考虑仅有一个元素的数组,易见数组最后一个元素的索引是长度减一。2
Which of the following declarations will cause a compile time error?
String
和int
的类型不匹配。4
What is returned from arr[3]
if arr={6, 3, 1, 2}
?
索引
3
对应数组第四个元素。2
What is returned from mystery
when it is passed {10, 30, 30, 60}
?
public static double mystery(int[] arr) { double output = 0; for (int i = 0; i < arr.length; i++) { output = output + arr[i]; } return output / arr.length; }
求数组的算数平均数,注意
output
的类型是double
。5
Given the following values of a
and the method doubleLast
what will the values of a
be after you execute: doubleLast()
?
private int[ ] a = {-10, -5, 1, 4, 8, 30}; public void doubleLast() { for (int i = a.length / 2; i < a.length; i++) { a[i] = a[i] * 2; } }
将数组后三个数翻倍。
3
0 条评论