Java Program on Addition Operator

In this article we will see the use of Addition operator in Java.

Java Program on Addition Operator

Addition operator is a binary operator and it is used to add two numbers. Addition operator is represented by the + symbol.

Syntax: operand + operand

Example:

Let’s understand it more clearly.

Suppose we have 2 variables a and b.

a=2

b=3

Then we can use addition operator like this.

result=a+b;  // here 2 variable operand added

(or)

result = 5 + a; // here one constant operand i.e. 5 and variable operand i.e. ‘a‘ added

Program:

import java.io.*;
 
class Main 
{
    public static void main(String[] args)
    {
        //Declaring variables
        int number1 = 10;
        int number2 = 20;
        int result = number1+number2;
        
        //print results
        System.out.println("By performing addition operation: " + result);
    }
}
Output:

By performing addition operation: 30

Our website provided core java programs examples with output aid beginners and expert coders to test their knowledge gap and learn accordingly.

Leave a Comment