Skip to Main Content
Java 6 Illuminated: An Active Learning Approach, 2nd Edition
book

Java 6 Illuminated: An Active Learning Approach, 2nd Edition

by Julie Anderson, Herve J. Franceschi
February 2008
Intermediate to advanced content levelIntermediate to advanced
1288 pages
39h 39m
English
Jones & Bartlett Learning
Content preview from Java 6 Illuminated: An Active Learning Approach, 2nd Edition
310 CHAPTER 6 Flow of Control,Part 2: Looping
Figure 6.11
Roll a Ball,Version 2
6.5 Type-Safe Input Using Scanner
One problem with reading input using Scanner is that if the next token
does not match the data type we expect, an InputMismatchException is gen-
erated, which stops execution of the program. This could be caused by a
simple typo on the users part; for example, the user may type a letter or
other nonnumeric character when our program prompts for an integer. To
illustrate this problem, Example 6.9 shows a small program that prompts
the user for an integer and calls the nextInt method of the Scanner class to
read the integer, and Figure 6.12 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second Edition

JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second Edition

Kathy Walrath, Mary Campione, Alison Huml, Sharon Zakhour
Java Illuminated, 4th Edition

Java Illuminated, 4th Edition

Julie Anderson, Hervé J. Franceschi

Publisher Resources

ISBN: 9780763749637