Numeric Input

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

Parameter 0: stringA
Parameter 1: stringB
Parameter 2: stringC

Numeric Input

The command line data are always Strings. But this does not prevent you from entering 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 );
  }
}

Say that the user started this program with the command line:

C:/>java InputDemo 23 87 13 67 -42

QUESTION 11:

Fill in the blank so that the program adds up all the numbers on the command line.