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.
and regarding option 1 (indicated as incorrect)
explanation isScanner sc = new Scanner(new File(fileName), ",");
But acctually there is such constructor http://docs.oracle.com/javase/6/docs/ap ... ng.String)There is no such constructor. Scanner does not take delimiter at instantiation. Scanner sc = new Scanner(new File(fileName)); is valid.
Code: Select all
public Scanner(File source,
String charsetName)
throws FileNotFoundException