Given an array of ints named x and an int variable named total that has already been declared, write some code that places the sum of all the elements of the array x into total. Declare any variables that you need.

Given an array of ints named x and an int variable named total that has already been declared, write some code that places the sum of all the elements of the array x into total. Declare any variables that you need.

LANGUAGE: JAVA

CHALLENGE:

Given an array of ints named x and an int variable named total that has already been declared, write some code that places the sum of all the elements of the array x into total. Declare any variables that you need.

SOLUTION:

total = 0;
int counter = 0;
while (counter < x.length){
   total = total + x[counter];
   counter++;
}

Add comment