J2SE Programming
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:-
Other ways will be discussed Later.
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
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 { //Main Function public static void main(String[] args) { Addition a1=new Addition(); int a=a1.add(10,20); System.out.println(Sum is : +a); } //Function to add two numbers public int add(int a,int b) { int c=0; c=a+b; return c; } } |
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