Section 2: How to Accept Input by using Scanner?
The class Scanner is present in package “java.util”. As shown in the example below, we are reading the values from user input.
Same as command-line arguments if we want to pass String containing space, we will pass it inside double-quotes. There are different types of methods for the Scanner class to accept various data type values as listed below.
Let’s check one more example to get 2 numbers from the user and display the addition. We will ask the user to enter the first and second numbers one by one, and display addition.
Next, we will see how to read by using BufferedReader.