Home Java Overview Maven Tutorials

Saturday, 4 November 2017

Scanner class in java with example

Hello friends,

In this article we will discuss about scanner class in Java:

Scanner class is used when we want Input from user.
In our example, we will take the name & age from user as input & will print these values.

For Video :- Click Here

import java.util.Scanner; public class Swap
public static void main(String args[])
Scanner scan = new Scanner(;
System.out.println("Enter Your Name");
String mystring =;
System.out.println("Enter Your Age");
int mynumber = scan.nextInt();
System.out.println("Your Name is :"+ mystring);
System.out.println("You are" + " "+ mynumber+ " " +"years old");

Output : Enter Your Name
Enter Your Age
Your Name is Chandan
You are 28 years old.

Tags :

What is Scanner class in Java

Example of scanner class in java

How to take input from user in java


  1. Very understandable tutorial, I could do everything from the first time! I have started to learn Java on this service only a few weeks ago, but I consider that I already have success in this sphere, and I wanna learn more and more!

  2. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. portable scanners for photos