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 );
 }
}
 
 
 
Comments
Post a Comment