Source Code : Show use of Argv to get an integer value from command line

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Show use of Argv to get an integer value from command line

Show use of Argv to get an integer value from command line
  

/** Show use of Argv to get an integer value from command line */
public class AddException {
  /** Main program */
  public static void main(String[] argv) {
    int number = 0;

    System.out.println("The number of words in argv is " + argv.length);

    if (argv.length == 0) {
      number = 1234;
    } else if (argv.length == 1) {
      try {
        number = Integer.parseInt(argv[0]);
      } catch(NumberFormatException e) {
        System.err.println("Number " + argv[0] + " invalid (" + e.getMessage() + ").");
        System.exit(1);
      }
    } else {
      System.err.println("usage: UseArgv number");
      System.exit(1);
    }

    System.out.println("OK, number is " + number);
  }
}



           
         
    
  

Thank with us