Introduction to Java Scanner Class
18 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is used in Java 5 and above to allow the user to enter their own values for the program?

  • Scanner class (correct)
  • PrintStream class
  • Hardcoded values
  • BufferedReader class

What is the problem with the program Add2Numbers.java mentioned in the text?

  • It doesn't use any classes
  • It has a syntax error
  • It always produces a result of 43 (correct)
  • It asks for too much user input

Which package does the Scanner class belong to?

  • java.util (correct)
  • java.awt
  • java.lang
  • java.io

What does the * in 'import java.util.*;' indicate?

<p>All classes are available to the compiler (C)</p> Signup and view all the answers

What do you need to create first in order to use the Scanner class?

<p>A Scanner object (B)</p> Signup and view all the answers

Which class allows reading keyboard input in a convenient manner in Java?

<p>Scanner class (C)</p> Signup and view all the answers

Which method of the Scanner class is used to read in an integer?

<p>nextInt() (C)</p> Signup and view all the answers

What does the following line of code do: c = keyboardIn.next().charAt(0);

<p>Reads a character from the input (B)</p> Signup and view all the answers

How is a string literal defined?

<p>A sequence of characters enclosed in quotation marks (B)</p> Signup and view all the answers

In Java, how can you create an instance of the Scanner class?

<p>By importing java.util.Scanner (D)</p> Signup and view all the answers

What does the method keyboardIn.nextDouble() do?

<p>Reads in a double value (D)</p> Signup and view all the answers

How is a value assigned to a string variable in Java?

<p><code>firstName = &quot;Mary&quot;;</code> (C)</p> Signup and view all the answers

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

<p>Reads a line up until it reaches a white space (D)</p> Signup and view all the answers

Which class represents objects of string literals in Java?

<p><code>String</code> (D)</p> Signup and view all the answers

What is used to construct a Scanner object for reading input from the keyboard?

<p><code>keyboardIn = new Scanner(System.in);</code> (A)</p> Signup and view all the answers

What is used to represent the keyboard in Java?

<p><code>System.in</code> (B)</p> Signup and view all the answers

Which method reads a line up until it reaches a white space?

<p><code>next()</code> (B)</p> Signup and view all the answers

What does the following line of code do: firstName = new String();?

<p>Calls constructor of empty string (C)</p> Signup and view all the answers

More Like This

Java Scanner Class Quiz
6 questions

Java Scanner Class Quiz

IntuitiveSparrow avatar
IntuitiveSparrow
Introduction to Java Scanner Class
18 questions
Java Scanner Class Overview
10 questions
Java Scanner Class Basics
8 questions

Java Scanner Class Basics

GratefulSerpentine4280 avatar
GratefulSerpentine4280
Use Quizgecko on...
Browser
Browser