User Input (Scanner) Review

User Input (Scanner) Review#

These questions are designed to assess your current understanding of using Scanners to read in user input!

Question 1 Which of the following code snippets shows the correct way to construct a Scanner that takes user input from the console?

  1. scanner input = new Scanner(System.in)

  2. Scanner input = Scanner(System.in)

  3. Scanner input = new Scanner(System.in);

  4. Scanner input = new Scanner();


Question 2 How many tokens are listed below?

hello!          I love 
       computer        Science!
1 2 3

Question 3 Which statement do we need at the very top of our program so that we can use Scanners?

  1. import java.util;

  2. import java.io.*;

  3. import java.util.*;

  4. import java.io;


Question 4 What Scanner methods can you use to read in this token of user input? hello

Select all methods that could apply

  1. next()

  2. nextDouble()

  3. nextInt()

  4. nextLine()

  5. Error!


Question 5 What Scanner methods can you use to read in this token of user input? 3.0

Select all methods that could apply

  1. next()

  2. nextDouble()

  3. nextInt()

  4. nextLine()

  5. Error!


Question 6 What Scanner methods can you use to read in this token of user input? 3

Select all methods that could apply

  1. next()

  2. nextDouble()

  3. nextInt()

  4. nextLine()

  5. Error!


Question 7 If I were to write a program to prompt the user asking them for their age, what Scanner method should I use to get that input?

Select all methods that could apply

  1. next()

  2. nextDouble()

  3. nextInt()

  4. nextLine()


Question 8 If I were to write a program to prompt the user asking them for their favorite season (e.g. winter, summer, autumn, or spring), what Scanner method should I use to get that input?

Select all methods that could apply

  1. next()

  2. nextDouble()

  3. nextInt()

  4. nextLine()