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.                            

  System.out.println("Enter your number");

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

  System.out.println("your number is "+a);


Enter your number


your number is 50

Next up

Read More Questions

If you are looking for answer to specific questions, you can search them here. We'll find the best answer for you.


Study Full Subject

If you are looking for good study material, you can checkout our subjects. Hundreds of important topics are covered in them.

Know More