What is the result?

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?

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.

Explanation:
Exception in thread “main” java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at main(Main.java:15)



Leave a Reply 1

Your email address will not be published. Required fields are marked *