Q:

Sum of array ,two same methods different result

I have two arrays ,i wan sum of elements,but in one method i just to results have list of elements in array.
Wrong array: 
 int[] names = {1, 24, 4, 50, 4, 1};

    int suma = 0;
    for (int i = 0; i < names.length; i++) {

        suma += names[i];

        System.out.println("suma" + suma);

    }

i have results :suma 1,suma 24...
but this is rigth:
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int sum = 0;
    for (int i = 0; i < numbers.length; i++) {
        sum += numbers[i];
    }
    System.out.println("The sum is: " + sum);

I'm confused.

A:

In the first code:
for (int i = 0; i < names.length; i++) {
  suma += names[i];
  System.out.println("suma" + suma);
}

there are two statements inside the scope of for {...}

suma += names[i];
System.out.println("suma" + suma);

Everytime the for loop runs it has two statements to execute. This is the reason why in the first case you're output is:
suma1
suma25
suma29
suma79
suma83
suma84

Because the System.out.println("suma" + suma); is executing names.length number of times.
In the second case however:
for (int i = 0; i < numbers.length; i++) {
  sum += numbers[i];
}

The loop has only one statement to execute names.length number of times. And the output is printed outside the loop that's why your output is:
The sum is: 55

