1.2 + 2.8 + 1.0 = 5.0
It is likely in answering the question (if you did) that you started with the beginning number, and then proceeded one by one through the remaining numbers. Of course, you recognize that pattern as the familiar counting loop.
Here is a program that sums the numbers in an array. This time, the array
is of double
, but that does not really change anything.
class SumArray { public static void main ( String[] args ) { double[] array = { -47.39, 24.96, -1.02, 3.45, 14.21, 32.6, 19.42 } ; // declare and initialize the total _____________ total = ____ ; // add each element of the array to the total for ( int index=0; index < array.length; index++ ) { total = _________________ ; } System.out.println("The total is: " + total ); } }