Page: How To Use Scanner Class in Java
0

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);
  }
}

Output:

Enter your number

50

your number is 50
ADD COMMENTlink
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.