Knowledge Walls
John Peter
Pune, Maharashtra, India
How to use scanner class in java with example
2684 Views
Hints 
Scanner class is used to read data from passed InputStream. Here it is explained how to read input by using java.util.Scanner. Below example to read user credentials by using Scanner class utility.
Example: Scanner.class
import java.util.Scanner;

class Solution {
    public static void main(String args[])throws Exception{
        Scanner scanner = new Scanner(System.in);
        
        System.out.println("Enter the username");
        String username = scanner.nextLine();
        
        System.out.println("Username: "+username);
    }
}
Output 
Enter the username
sarathy

Username: sarathy
Previous Topics
Previous lessons of current book.
Computer software engineer articles of One day One Thing to Know
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details