Parameter 0: stringA Parameter 1: stringB Parameter 2: stringC
The command line data are
always String
s.
But this does not prevent you
from entering numbers.
Use
or
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:
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.