How Do You Write a Java Program to Accept Text from the Command Terminal and Print It Back Out?

Problem scenario
You want to write a basic Java program to test it out.  How do you write a program to accept user input, specifically a alphanumeric input, and print it back to the screen?

1.  Install the Java Development Kit if you have not installed it yet.  If you are not sure you have it, run "javac -version".  If it says that the command is not found, you need to install the Java Development Kit.  If you do not know how, see this posting.

2.  Create this file named

import java.util.Scanner;

public class acceptText {

public static void main(String[] args) {
   System.out.println("Please enter text, then press enter: ");
   Scanner x = new Scanner(;
   String var1 =;

3.  Run this command: javac

4.  Run this command: java acceptText

Leave a comment

Your email address will not be published. Required fields are marked *