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 ...



![import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner myInput = new Scanner(System.in); System.out.println("Type your message ! : "); String myMessage = myInput.nextLine() ; System.out.println(" You have entered " + myMessage ) ; } }](https://3.bp.blogspot.com/-yJrPv1ru0ZE/WQQkitzTHYI/AAAAAAAAAXU/n7yfAzdLHFYRXMoRS6WpYFUkqw2gfLtVACLcB/s1600/11.png)