Chapter 5-Getting Input From The User
Chapter 5-Getting Input From The User
THE USER
Prepared by: Ms. Jullie Ann M. Ocampo
1
Getting Input from the Keyboard
Two Methods On Getting Input From
The Keyboard
▪ Text-based (Scanner)
2
Text-Based
4
Line 5, display the string “Enter a number: “ in
the screen.
Line 6, instantiate the Scanner class and
store the object into the variable scan
5
Line 7, scan the value to be inputted form the
keyboard and store it to the variable num
using the method nextInt();
Line 8, display the string “You enter” together
with the value of num
6
Reading Different Data Types Using
Scanner
8
Line 1, import the class JOptionPane inside
javax.swing
Line 3, start of the class GUIBasedInput
Line 4, start of main method
Line 5, showInputDialog will display a dialog
box with the string “Enter a number: ”
9
Input of the user will be store in variable input
Line 7, showMessageDialog will display a
dialog box that will display the string “You
enter ” with the value of input variable
10
Converting String to Numeric Data
Type