Parameter 0: 123 Parameter 1: 0045.7
Exactly the characters on the command line are printed.
The command line data are
always Strings.
If you want numbers you need to do a conversion.
Use
Integer.parseInt(String)
or
Double.parseDouble(String)
to convert the character data to numeric data.
The Integer class is a wrapper class
that contains several useful methods, such as this
one for converting between characters and int.
The Double class is also a wrapper class.
Here is an example:
public class InputDemo
{
public static void main ( String[] args )
{
int sum = 0;
for (int j=0; j < args.length; j++ )
sum += Integer.parseInt( );
System.out.println( "Sum: " + sum );
}
}
Say that the user started this program with the command line:
C:\>java InputDemo 23 87 13 67 -42
Fill in the blank so that the program adds up all the numbers on the command line.