Reading Data from the Keyboard
In order to read the data from the keyboard java has a scanner class , scanner class has a lot of methods to read the data from the keyboard.
Scanner reference = new Scanner (System.in);
Where Scanner is the class name in java and reference is the variable name and new is for creating new object of scanner class and System.in is used for getting system input from user.
int a = reference.nextInt();
is a representation of getting user input as an integer form with the help of the keyboard.
by calling the reference variable by nexInt() method.
Please Click for the Notes PDF of this concept : Notes PDF
package scannerclassinjava;
// how to do user input in java using scanner class
/*
step 1 = import the scanner class (done)
step 2 = make the scanner class object (done)
step 3 = call the variable from ref variable of scanner class(done)
*/
// import java.util.*; for importing all the classes of util package
import java.util.Scanner;
public class ScannerClassInJava {
public static void main(String[] args) {
Scanner ref = new Scanner(System.in);
System.out.println("Please enter your Age");
byte age = ref.nextByte();
byte age2=ref.nextByte();
System.out.println("Your firts Age is "+age+" and your second age is "+age2);
}
}