MegaMan (megaman) wrote,
MegaMan
megaman

  • 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.

http://java.sun.com/docs/books/tutorial/essential/attributes/cmdLineArgs.html
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments