Java Reference
In-Depth Information
Display 2.5
The DecimalFormat Class (part 2 of 2)
Sample Dialogue
Pattern 00.000
12.346
Pattern 0.00
12.35
Pattern 0.00
$19.80
Pattern 0.00%
30.80%
Pattern #0.###E0
1.2346E2
Pattern 00.###E0
12.346E1
Pattern #0.###E0
12.346E-6
Pattern 00.###E0
12.346E-6
The number is always given, even if
this requires violating the
format pattern.
2.2
Console Input Using the Scanner Class
Let the world tell me.
FRANK SHAKESPEARE,
Franky I
Starting with version 5.0, Java includes a class for doing simple keyboard input. In this
section, we show you how to do keyboard input using this class, which is named Scanner .
The Scanner Class
Display 2.6 contains a simple program that uses the Scanner class to read two int
values typed in on the keyboard. The numbers entered on the keyboard are shown in
bold . Let's go over the Scanner -related details line by line. The following line, which
should be placed near the start of the file, tells Java where to find the definition of the
Scanner class:
import java.util.Scanner;
This line says the Scanner class is in the java.util package; util is short for utility ,
but in Java code, you always use the abbreviated spelling util . A package is simply a library
of classes. This import statement makes the Scanner class available to your program.
import
 
 
 
Search WWH ::




Custom Search