go to previous page   go to home page   go to next page

Answer:

Parameter 0: 123
Parameter 1: 0045.7
 

Numeric Input

The command line data are always Strings. But strings of digits may be converted to numbers. 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:


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 );
  }
}

QUESTION 12:

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.