Java Program to Add Two Numbers Using Command Line Arguments

Write a Java program to add two numbers by taking command line arguments.



Source Code
class CmdLineArgDemo {

	public static void main(String[] args) {

		int no1 = Integer.parseInt(args[0]);
		int no2 = Integer.parseInt(args[1]);
		
		int sum = no1 + no2;
		System.out.println("Addition of two numbers is "+sum);
	}

}
Output
C:\>javac CmdLineArgDemo.java
C:\>java CmdLineArgDemo 10 21
Addition of two numbers is 31