About Question com.enthuware.ets.scjp.v6.2.124 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
xpst
Posts: 2
Joined: Sun Jan 06, 2013 9:38 am
Contact:

About Question com.enthuware.ets.scjp.v6.2.124 :

Post by xpst »

There are several errors with this question:

Code: Select all

Identify the valid code fragments regarding java.text.Scanner. Assume that appropriate packages are imported and scanner is a Scanner object.
1) Scanner sc = new Scanner(new File(fileName), ",");
2) scanner.setDelimiter(",");
3) scanner.useDelimiter("[0-9]");
4) if(scanner.hasNextBoolean()) System.out.println(scanner.next());
5) if(scanner.hasNext()) System.out.println(scanner.nextBoolean());
6) Scanner sc = new Scanner("this is input text", ",");

options 3,4,5 are correct according to explanation.
Class Scanner is from java.util.Scanner package, not from java.text.Scanner

and regarding option 1 (indicated as incorrect)
Scanner sc = new Scanner(new File(fileName), ",");
explanation is
There is no such constructor. Scanner does not take delimiter at instantiation. Scanner sc = new Scanner(new File(fileName)); is valid.
But acctually there is such constructor http://docs.oracle.com/javase/6/docs/ap ... ng.String)

Code: Select all

public Scanner(File source,
               String charsetName)
        throws FileNotFoundException

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.124 :

Post by admin »

You are right. It should be java.util.Scanner.
However, the option explanation is correct. The constructor that you are referring to using character set as the second parameter and not a delimiter. "," is not a valid character set.

The explanation has now been enhanced to make that clear.

thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests