Given: 22. public void go(){ 23. String o = ""; 24. z: 25. for(int x=0; x<3; x++){ 26. for(int y=0; y<2; y++){ 27. if(x == 1) break; 28. if(x==2 && y==1) break z; 29. o = o + x + y; 30. } 31. } 32. System.out.println(o); 33. } What is the result when the go() method is invoked?
(A) 00
(B) 0001
(C) 000120
(D) 00012021
(E) Compilation fails. F. An exception is thrown at runtime.

答案:登入後查看
統計: A(17), B(39), C(278), D(19), E(48) #1157009

詳解 (共 2 筆)

#4178497

這題要注意break跳向哪邊
第一次跳的時候回到y第二次跳的是x
跑下來就會變成
X = 0  Y=0
X = 1 跳到 Y的迴圈 Y=0
Y=1 跳到X的迴圈 X =2
Y從0開始跑 Y=0
X<3 所以直接跳出
答案就是 000120

有誤解或有錯請指教

0
0
#1263844
Given:
22. public void go(){
23. String o = "";
24. z:
25. for(int x=0; x<3; x++){
26. for(int y=0; y<2; y++){
27. if(x == 1) break;
28. if(x==2 && y==1) break z;
29. o = o + x + y;
30. }
31. }
32. System.out.println(o);
33. }

What is the result when the go() method is invoked?
(A) 00
(B) 0001
(C) 000120
(D) 00012021
(E) Compilation fails. F. An exception is thrown at runtime.
0
0