SCJP 1.6版考題 170

出自 陳富國維基館
於 2013年3月30日 (六) 02:15 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: Given: 12. String csv = "Sue,5,true,3"; 13. Scanner scanner = new Scanner(csv); 14. scanner.useDelimiter(","); 15. int age = scanner.nextInt(); What is the result? A. Compila...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
Given:
12. String csv = "Sue,5,true,3";
13. Scanner scanner = new Scanner(csv);
14. scanner.useDelimiter(",");
15. int age = scanner.nextInt();

What is the result?
 A. Compilation fails.
 B. After line 15, the value of age is 5.
 C. After line 15, the value of age is 3.
 D. An exception is thrown at runtime.

解答


Ans: D

解說:

15. int age = scanner.nextInt();會讀到第一個以逗點隔開的整數,
但是csv第一個是Sue,不是整數,執行時會產生一個例外!