In order to make the user interact with his keyboard, java has a special class called Scanner. To use this class you must:
- Import the java.util.Scanner package
- Make an instantiation :
- Retrieve keyboard input in a Java variable:
- Final code :
Note
We do not always use nextLine () to retrieve a keyboard entry, the trick we use will be according to the nature of the input:
- nextInt () : if the input is an integer
- nextDouble () : if the input is a double variable
- nextLong () : if the input is a variable of type long ...