package Lesson1;
import java.util.Scanner;
public class UserInput {
public static void main(String[] args) {
Scanner user_input= new Scanner(System.in);
System.out.println("Enter some characters");
String user_input_word= user_input.nextLine();
System.out.println("The entered word is");
System.out.println(user_input_word);
}
}
First to take input from the user requires the use of built in Scanner class in java. It basically reads the data that user provides. Then we need to create a new object for this class which is user_input in my case and then we specify the source of data for it which is System.in, which basically means the system input and in my case the input is given from the keyboard. So the scanner scans whatever I am providing from the keyboard.
The following is the output of above code when executed.
You can copy/paste this code into your Eclipse IDE. First create package named Lesson 1 and within the package create a class named UserInput. Copy/paste this code and run yourself.