There's nothing wrong with the above code. The error you are getting is because when running the program (java keita), you are not parsing enough arguments, so the execution fails. If you try:
java keita 10 5
you will find that it works. To work around this, you could either check in an if-statement if the amount of arguments is equal to 2. If it's not, then print something like "insufficient arguments", or you could put your code inside a try-catch statement.
Regards!
|