Now I am going to write a program which adds two numbers.
For this i just want to know about addition operator and two inputs.
As we know, there is one operator known as plus(+) operator can be used to add two inputs.
Now the problem is how to get input for adding numbers.
There are three ways to get input as follows:-
- One way is just by assigning values.
- Second way is by User input during Run-time.
- Third way is using Command-Line arguments.
Other ways will be discussed Later.
| class Addition
public static void main(String args)
Addition a1=new Addition();
System.out.println(Sum is : +a);
//Function to add two numbers
public int add(int a,int b)
Now save it as Addition.java
Compile it using "javac Addition.java" Command in CMD
After compilation Run it using command "java Addition" in CMD