0
How To Use Scanner Class in Java

What is Scanner Class in Java?

Scanner is a class which is available in java.util package. and it is used to read input or data from the keyboard. By the help of Scanner class, we can take the input of the users from the keyboard.

How to use Scanner Class in Java?

import java.util.Scanner;   // we have to import Scanner

class Demo
{

public static void main(String args[])
{

Scanner sc = new Scanner(System.in); //(System.in) provide the environment for taking input from keyboard.

int a = sc.nextInt(); // for taking integer type value to the user

}
}


Output:

Enter your number

50