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

No comments:

Post a Comment