Log in

No account? Create an account
18 May 2004 @ 08:35 pm
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.

Current Mood: CAPCOM
Current Music: nothing