How to take input from user in java

In this Java example, we will read how to take input from user in Java.

We will use Scanner class to take the input from user


import java.util.Scanner;  

class JavaPrograms {
  public static void main(String[] args) {
    Scanner obj = new Scanner(;  
    System.out.println("Enter anything...");
   //Read the user input data
    String data = obj.nextLine();
	//Display the User input data on screen
    System.out.println("Entered data is: " + data);  



Enter anything...
Entered data is: