I do not know what your teacher gave it to you and if you already covered Exceptions, but that what you get when you use BufferedReader
getLine().
Check this
tutorial and you should be able to figure it out what to do with it. Main difference between yours code and code in the tutorials is that you read from command line and tutorial do it from a file