Program using Command line arguments in java
Program using Command line arguments in java
Before heading towards the Program using Command line arguments in java , we must have a little bit understanding about command line arguments
Now, In this Program to Add Two Numbers using Command line arguments in java, you should have the knowledge of following topics:
1.Accepting Inputs Through Command Line Arguments In Java
2.Variables and Data Types
3.Operators
class AddNos { public static void main(String [] args) { int num1,num2,sum; num1=Integer.parseInt(args[0]); num2=Integer.parseInt(args[1]); sum=num1+num2; System.out.println("first no="+num1); System.out.println("second no="+num2); System.out.println("Sum of "+num1 +" & "+num2 +" is: "+sum); } }
Output:
C:\Users\TCA\Programs>javac AddNos.java C:\Users\TCA\Programs>java AddNos 10 5 first no=10 second no=5 Sum of 10 & 5 is: 15
Most Importantly as mentioned above Java uses all the mathematics operation therefore by Changing (+) operator, we can subtract (-), multiply (*), divide (/), floor divide (//) or find the remainder (%) of two numbers.
Related Program
1.Java Program to find the area of Triangle
2.Java Program to Solve Quadratic Equation
3.Java Program to Generate a Random Number
Ask your questions and clarify your/others doubts by commenting. Java Documentation[/vc_column_text][/vc_column][/vc_row]