public static double average( double... numbers ) { 
    double total = 0.0; 
    [B][I][COLOR="Red"]for (double d : numbers)[/[/COLOR]I][/B] { 
        total += d; 
    return total / numbers.length; 

can any one explain the line bold
if posseble d program too...

Edited 3 Years Ago by mike_2000_17: Fixed formatting

"Enhanced for loop" - new in Java 1.5, and very good.
Read it as "for each double d in numbers"
It copies each element of numbers in turn to a new double, and executes the loop once for each.
You can use this for arrays, lists, all kinds of collections, eg:

ArrayList<String> someStrings = // create and populate the arraylist of Strings
for (String s : someStrings) {
   // this is executed once for each String in someStrings.
   // the value of each String is in variable s

for (double d : numbers) {
total += d;

is equivalent to:

for (int i=0; i<numbers.length;i++){
double d = numbers[i];
total += d;

Edited 6 Years Ago by tong1: n/a

This question has already been answered. Start a new discussion instead.