Java OCA OCP Practice Question 866

Question

Which line of code tells a scanner called sc to use a single digit as a delimiter?

A.  sc.useDelimiter("d"); 
B.  sc.useDelimiter("\d"); 
C.  sc.useDelimiter("\\d"); 
D.  sc.useDelimiter("d+"); 
E.  sc.useDelimiter("\d+"); 
F.  sc.useDelimiter("\\d+"); 


C.

Note

The + sign matches one or more occurrences, so it won't match just a single digit.

The correct string is "\d"; the extra escape is consumed by the Java compiler when it builds the literal string.




PreviousNext

Related