mathajax

Java CommandLine Argument

It explains how to read arguments from commandline and how to use it in adding two numbers program.


CommandLine Argument

  • The inputs passed along with the program execution start up command are called commandline aruguments
  • example - java CommandArgs 10 20
  • java - interpreter start executing a program
  • CommandArgs - It is program need to be executed by the interpreter.
  • 10 20 - These are commandline arguments passed to the program.
  • A main function of the program receives these commandline arguments as a string array parameter.

CommandLine Arguments - Java program

The java program reads two inputs from command line, sum it and prints the result.

 

public class CommandArgs {
  
   public static void main(String[] args) {
        
   int a = Integer.parseInt(args[0]);
   int b = Integer.parseInt(args[1]);
   int c = a+b;
   System.out.println( " Sum of Two numbers :" +  c );

 }
}


CommandLine Arguments - Compile,Execution and Output

Comments

Popular posts from this blog

Solving System of Linear Equations by Gauss Jordan Elimination

Matrix Forward and Back Substitution

Solve System of Linear Equations by LU Decompose

Matrix Determinant by Upper Triangular Matrix

Chebyshev distance between two points