nerdexam
Oracle

1Z0-851 · Question #65

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?

The correct answer is D. An exception is thrown at runtime. Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at Breaker.main(Breaker.java:8)

Analyzing and Troubleshooting System Problems

Question

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?

Options

  • ACompilation fails.
  • BAfter line 15, the value of age is 5.
  • CAfter line 15, the value of age is 3.
  • DAn exception is thrown at runtime.

How the community answered

(39 responses)
  • A
    13% (5)
  • B
    8% (3)
  • C
    3% (1)
  • D
    77% (30)

Explanation

Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at Breaker.main(Breaker.java:8)

Topics

#Java Scanner#delimiter#InputMismatchException#token parsing

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice