Page: 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(; //( 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
modified 20 months ago by gravatar for Yashbeer Yashbeer170 written 21 months ago by gravatar for anuragsingh07378 anuragsingh0737830
Please log in to add an answer.