SCJP 1.6版考題 157

出自 陳富國維基館
於 2013年3月30日 (六) 02:41 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: Given that c is a reference to a valid java.io.Console object, and: 11. String pw = c.readPassword("%s", "pw: "); 12. System.out.println("got " + pw); 13. String name = c.readLine(...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
Given that c is a reference to a valid java.io.Console object, and:
11. String pw = c.readPassword("%s", "pw: ");
12. System.out.println("got " + pw);
13. String name = c.readLine("%s", "name: ");
14. System.out.println(" got", name);
If the user types fido when prompted
for a password, and then responds
bob when prompted for a name,

what is the result?
A. pw:
   got fido
   name: bob
   got bob
B. pw: fido
   got fido
   name: bob
   got bob
C. pw:
   got fido
   name: bob got bob
D. pw: fido
   got lido
   name: bob got bob
E. Compilation fails.
F. An exception is thrown at runtime.

解答


Ans: E

解說:

 此程式片段有二個錯誤
 String pw = c.readPassword(“%s”, “pw: ”); 改:
 char[] pw = c.readPassword("%s", "pw: ");
 System.out.println(“ got”, name); 改 System.out.println(" got“ + name);