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.                            

  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
0  upvotes

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.

Search

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