Java Program Addition Of Two Numbers - 4 Ways | Programs
Beginners Programs :

Java Program Addition Of Two Numbers – 4 Ways | Programs

Java program to print or calculate addition of two numbers with sample outputs and example program. Addition of two numbers program is quite simple one, we do also wrote the program in five different ways using standard values, command line arguments, classes and objects, without using addition+ operator, method, BufferedReader with sample outputs and code.

  • How to add numbers ?

Well:P Do you really need explanation for this ? I think not.

  • Let’s get into programming part.

Java Program To Print Addition Of Two Numbers

1. Standard Method Function

Output:
 

2. Using command line arguments 

There you go another method using command line arguments : If you have no idea about what are command line arguments in Java. Do check it out complete guide here – what are command line arguments in java with examples.

Output:

3. Using classes and Objects

Print addition of numbers : Another sample program using objects and classes

Output:

 

4. Without Using Addition+ Operator

You can even write the program without using the + operator here is the sample code – Learn more what are different types of operators in Java with examples.

Output:

 

5. Using Method

Example program #5 : Using method calling to print the addition of two numbers.

Output:

 

6. Using Buffered Reader

To Print addition of numbers using BufferedReader with sample output.

Output:

For You:

Here is the list of other programs for you:

  • Hi,

    Very useful article on addition program in java. Thanks for sharing.

    Cheers,
    http://www.flowerbrackets.com/addition-program-in-java/

  • Omar Sakib

    public class Function {

    int r;
    int addition(int a,int b){

    r=a+b;
    return r;
    }
    public static void main(String[] args) {

    Function z=new Function();
    z.addition(5,6);

    System.out.println(“The function is: “+z.r);

    }
    }