for ( double val : array )
total += val ;
Here is the revised program:
class SumArrayRevised
{
public static void main ( String[] args )
{
double[] array = {} ;
// declare and initialize the total
double total = 0.0 ;
// add each element of the array to the total
for ( double val : array )
total += val ;
System.out.println("The total is: " + total );
}
}
But the array has no elements!! Will the program compile? Will the program run? What is the sum of an array with no elements?