Page 1 of 1

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

Posted: Sat Jan 12, 2013 4:34 pm
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

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

Posted: Sat Jan 12, 2013 4:49 pm
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!