Which of the following statements are true about Scanners. Select all that apply
ID: 3723040 • Letter: W
Question
Which of the following statements are true about Scanners. Select all that apply.
Answers:
The Scanner object throws an InputMismatchException when incorrect input types are read
Scanners are located in the java.io package
Scanners can be used to read a single character from the input stream
The delimiter of a Scanner can be changed to something other than whitespace
Scanners can be connected to both input and output files
Only one Scanner object is allowed in the same scope of a program
Explanation / Answer
(a) True
The type of error thrown is InputMismatchException . It is thrown in case input does not matches the expected input.
(b) False
Scanner are located in the java.util package.
(c) True
A single character can be read. But it is read as a String. We can extract a single character from the String.
We can use the following code
char ch = scan.nextLine().chatAt(0);
Here,
(d) True
The delimeter can be changed using the
useDelimiter(String pattern)
function.
(e) True
We can read and write with Scanner object.
(f) False
More than 1 Scanner objects can be created in the same scope.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.