2009年2月9日 星期一

第48題

Given:
1. public class Venus{
2. public static void main(String[] args){
3. int[] x = {1, 2, 3};
4. int y[] = {4, 5, 6};
5. new Venus().go(x, y);
6. }
7. void go(int[]... z){
8. for(int[] a : z)
9. System.out.print(a[0]);
10. }
11. }
What is the result?
A. 1
B. 12
C. 14
D. 123
E. Compilation fails.
F. An exception is thrown at runtime.
答案:C
參考:5-1 陣列基本概念、6-2 Java 方法

---------------------------------------------

5. new Venus().go(x, y);
>7. void go(int[]... z){ //z has int[] x = {1, 2, 3}; int y[] = {4, 5, 6};
>8. for(int[] a : z) //for each z, x array in first loop, y array in second loop.
>9. System.out.print(a[0]); //output 1 (x[0]) then output 4 (y[0]).

沒有留言:

張貼留言