Use an editor or IDE to type in the source code and then compile it and execute it.

See the API doc for the Scanner class and the String class for useful methods to do what you want.