First start with definition of Array
- An array is a container object that holds a fixed number of values of a single type.
- The length of an array is established when the array is created.
- After creation, its length is fixed.
Example :

So lets see what you process you need to do your addition here ?
Loops
The definition of loops :
If you need to execute some block of code more than one time or iterate over a range of values, loop is used.
There 3 different ways of looping in Java
Name Synatx
1. for loop
for(initialization; Boolean_expression; update){ //Statements}
while loop
while(Boolean_expression){//Statements}
do while loop
do{//Statements }while(Boolean_expression);
Based on the definition of loop in Java, you need to use looping here because you want to do addition
as many times as necessary
Lets solve your issue with while loop
you need a accumulator variable like
int sume = 0;
Follow the syntax of for loop
for(initialization; Boolean_expression; update)
{
//Statements
}
so your whole code become :
int sum = 0;
for(int i=0; i< array1.length; i++){
sum = sum + array1[i]
}
you will start from index zero and keep adding till index is going to be less than length of array why because array index starts from zero in java.
Inside for loop, you add the content of each elements to accumulators in order to derive the sum that you are looking for .