MegaMan (megaman) wrote,

  • Mood:
  • Music:
Parsing Numeric Command-Line Arguments

If your program needs to support a numeric command-line argument, it must convert a String argument that represents a number, such as "34", to a number. Here's a code snippet that converts a command-line argument to an int:
int firstArg;
if (args.length > 0)
firstArg = Integer.parseInt(args[0]);

parseInt throws a NumberFormatException if the format of args[0] isn't valid. All of the Number classes--Integer, Float, Double, and so on--have parseXXX methods that convert a String representing a number to an object of their type.

  • The 21st Century!

    I feel like I got a lot of value out of liveJournal years ago. I don't think anyone reads this, so that's fun. I have so much hate and resentment…

  • (no subject)

    Hi Livejournal!

  • A legitimate, Retro, Old School LiveJournal Entry

    Well Hello Livejournal! To be honest, Livejournal is not as fun without a huge audience. Facebook has really replaced everything that livejournal…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded