2

Recently I have been making a little java game where you build up a city and have to defend it. Now I want to make it ready for proper testing. I was thinking of having the server running on an old computer of mine, than I would have to make it so that, while the program is running, I can type in commands that will be executed. Like the minecraft or craftbukkit servers have. There you can type in text and press enter in the same console as where you started the program. Anybody got any ideas?

1 Answer 1

2

Sounds like you just need a Scanner object.

For example, to continuously wait for input and then print that input, you would write:

Scanner s = new Scanner(System.in); 
String foo = s.nextLine();
System.out.println(foo);

System.in as the constructor parameter specifies that you are reading input from the keyboard (as opposed to a file, for example).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.