Hi, I need help on this Sum problem. I want to add all the array elements into one value which is '19.0', instead it prints out:
1.0
3.0
7.0
12.0
18.0
as I want to use the sum output later, I only want it to have 1 value, instead it has many.
any help?
one value which is '19.0' = '18.0'
sorry! Typo
1.0
3.0
7.0
12.0
18.0
as I want to use the sum output later, I only want it to have 1 value, instead it has many.
any help?
public class hi {
public static void main(String[] args) {
double[] ra = {1.0, 2.0, 4.0, 5.0, 6.0};
Sum(ra);
}
public static void Sum(double[] a){
double sum = 0;
for (int i = 0; i < a.length; i++){
sum+= a[i];
System.out.println(sum);
}
}
}
one value which is '19.0' = '18.0'
sorry! Typo