In this example we will show you how to read user input in Java.
Source Code
package com.beginner.examples;
import java.util.Scanner;
class ReadInput {
public static void main(String[] args) {
String input;
// enter your input
Scanner s = new Scanner(System.in);
System.out.println("Enter your input");
input = s.nextLine(); //read your input
System.out.println("Your input is: " + input );
}
}
Output:
Enter your input
Your input is: 123
References
Imported packages in Java documentation: