We can perform the addition (sum) of two or more numbers by using the arithmetic operator (+). To write an addition program in Java, one must understand how the + operator works. In this section, we will create Java programs that add two or more numbers.

Using Command-Line Arguments

```class AdditionExample1
{
public static void main(String[] args)
{
int x = Integer.parseInt(args);
int y = Integer.parseInt(args);
int sum = x + y;
System.out.println("The sum is: " +sum);
}
}```

Output:

`The sum is: 17`

Explanation: In the above example, a point to be noted that we have not initialized any number. Instead of initializing the number, we will pass the numbers as argument at the time when we specify the java command.

The first argument will be store in the variable x and the second argument will be store in the variable y. Remember that the numbers that we have parsed as an argument in String and we cannot perform the addition. So, we need to convert these arguments in the integer by using the parseInt() method of the Integer class.

Let’s see another program.

```public class AdditionExample2
{
public static void main(String[] args)
{
int a = 5, b = 6; //a and b are two operands
int add; //a variable that stores the final result
//printing the result
System.out.println("Addition of " + a + " and " + b + " is " + add);
}
}```

Output:

`Addition of 5 and 6 is 11`

The addition operation is not only confined to two operands. We can have n numbers of operands on which we can perform the addition operation. In such a scenario, we either take the help of Java for loop (iterative approach), or we choose the recursive approach. Let’s discuss the iterative approach first.

Iterative approach

The following program demonstrates how to add array elements.

```public class AdditionExample3
{
public static void main(String[] args)
{
int arr[] = {4, 56, 230, 5, 598, 232, 348, 23, 54, 2, 72, 4, 345};
int add = 0; //a variable that stores the result
//Iterating over every element of the array and performing addition
for(int i = 0; i < arr.length; i++)
//printing the result
System.out.println("Total sum is: " + add);
}
}```

Output:

`Total sum is: 1973`

Explanation: In the above example, we have created an array arr[] and inserted some numbers into it. We have taken another variable add and initialized it to 0. It stores the sum of numbers that array contains. We have used a Java for loop that iterate over the array and fetch the numbers. After that, we are finding the cumulative sum and storing the sum in the addvariable.

We can achieve the same result using the recursion, also.

Recursive Approach

```public class AdditionExample4
{
public static int addUsingRec(int input[], int index)
{
//handling the base case
if(index >= input.length) return 0;
return input[index] + addUsingRec(input, index + 1);
}
public static void main(String[] args)
{
int arr[] = {4, 56, 230, 5, 598, 232, 348, 23, 54, 2, 72, 4, 345};
int add; //it will contain the final result
//printing the result
System.out.println("Total sum is: " + add);
}
}```

Output:

`Total sum is: 1973`

Explanation: The approach is similar to the iterative one. The only difference is instead of Java-for loop, we have used the recursion for doing the iteration.