【系統公告】頁面上方功能列及下方資訊全面更換新版,『舊用戶且擁有VIP』可再切回舊版。 前往查看

OJCP(SCJP)題庫下載題庫

上一題
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.


答案:登入後觀看
難度: 簡單
1F
Joe Chen (2016/02/20)
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.
2F
Mata 高三下 (2020/07/28)

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

有誤解或有錯請指教

Given: 22. public void go(){ 23. Strin..-阿摩線上測驗