Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Add Command line integers

  • args
  • Integer
  • parseInt
public class AddCmdLineNumbers{
    public static void main(String[] args){
        if (args.length != 2) {
            System.out.println("Must have exactly 2 values on the command line");
            System.exit(1);
        }
        System.out.println("First: " + args[0]);
        System.out.println("Second: " + args[1]);
        System.out.println(Integer.parseInt(args[0]) + Integer.parseInt(args[1]));
    }
}


javac AddCmdLineNumbers.java
java AddCmdLineNumbers 19 23