NEW
Font size
WorksheetsJava Scanner Class Quiz
Total questions: 10
Worksheet time: 2mins
Which package contains the Scanner class in Java?
java.io
java.util
java.lang
java.input
Which of these is the correct way to create a Scanner object for reading from the keyboard?
Scanner sc = new Scanner(System.out);
Scanner sc = new Scanner("input.txt");
Scanner sc = new Scanner(System.in);
Scanner sc = Scanner.create();
Which Scanner method is used to read an integer from user input?
sc.readInt()
sc.nextInt()
sc.getInt()
sc.integer()
Which Scanner method reads a complete line of text as a String?
What is the purpose of the sc.close() method?
A) To clear the Scanner buffer
B) To stop accepting input
C) To release system resources associated with Scanner
D) To reset Scanner to default state
Which of the following Scanner methods is used to read a double value?
A) sc.nextDouble()
B) sc.readDouble()
C) sc.getDouble()
D) sc.doubleValue()
What does sc.next() return?
A) A full line of input
B) The next integer
C) The next word (until a space)
D) The next character
Which method is used to read a boolean value from the Scanner?
A) sc.nextBool()
B) sc.readBoolean()
C) sc.nextBoolean()
D) sc.getBoolean()
What should be imported to use the Scanner class?
A) import java.Scanner;
B) import java.util.*;
C) import java.util.Scanner;
D) import java.io.Scanner;
Which of these data types is NOT directly supported by Scanner class methods?
A) int
B) float
C) char
D) boolean
