wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Scanner Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the purpose of the Java Scanner class?

a)

To create graphical user interfaces

b)

To read input from various sources

c)

To manage file outputs

d)

To perform mathematical operations

2.

Which method would you use to read a byte value using a Scanner object?

a)

nextByte()

b)

nextInt()

c)

nextDouble()

d)

next()

3.

What does the `nextLine()` method of the Scanner class do?

a)

It reads a single character

b)

It reads the next token from the input

c)

It reads the next line of text

d)

It reads an integer value

4.

Which import statement is necessary to use the Scanner class in Java?

a)

import java.util.Scanner;

b)

import java.util.*;

c)

import java.Scanner;

d)

import Scanner;

5.

How do you create a new Scanner object to read from standard input in Java?

a)

Scanner scan = new Scanner(System.in);

b)

Scanner scan = new Scanner(System.out);

c)

Scanner scan = new Scanner();

d)

Scanner scan = System.in;

6.

Which method of the Scanner class should be used to check if there is another integer input available?

a)

hasNextInt()

b)

hasNext()

c)

nextInt()

d)

checkInt()

7.

What is the output of `nextDouble()` when used with a Scanner object?

a)

A string

b)

An integer

c)

A double

d)

A boolean

8.

To read a full name including spaces using Scanner, which method should you use?

a)

next()

b)

nextLine()

c)

readString()

d)

readLine()

9.

What happens if you use `nextInt()` to read an input that is not an integer?

a)

The program will convert it to an integer

b)

The program will skip the input

c)

The Scanner throws an InputMismatchException

d)

The program will terminate

10.

Which method from the Scanner class is best for reading a single word from the user input?

a)

nextLine()

b)

next()

c)

read()

d)

readWord()

11.

How can you close a Scanner object named `scan`?

a)

scan.close();

b)

scan.end();

c)

close(scan);

d)

end(scan);

12.

What is the correct way to read a boolean value using Scanner?

a)

nextBoolean()

b)

nextBool()

c)

readBoolean()

d)

getBoolean()

13.

If you want to use a delimiter other than whitespace in Scanner, which method should you use?

a)

setDelimiter()

b)

useDelimiter()

c)

delimiter()

d)

setDelimit()

14.

Which method would you use to read a long integer using a Scanner object?

a)

nextLong()

b)

nextInt()

c)

nextDouble()

d)

next()

15.

What does the `hasNext()` method of the Scanner class check for?

a)

If the next input matches an integer

b)

If there is another line in the input

c)

If there is any input available regardless of its type

d)

If the input is a valid Java identifier