• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input question  RSS feed

 
Kev Woo
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to get input from the user when they execute my program from a unix command shell. In my case how many times my program will run a Craps simulation...

it should look like this

java SimCraps number

I have the code to run the simulation i just don't know what input methods to use in order to get input like this.

Thanks
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll use the String[] args parameter that gets passed into your main method to get the user's input. First get its length to be sure that a parameter was passed (in this situation, args.length > 0), then get the 0'th item in this array, convert it to int with Integer.parseInt(...) and you're off!

Luck!
 
Kev Woo
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. Very helpful
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!