Monday, March 5, 2012

Challenge 044: Variety is the Spice of Life


for loop:

int sum = 0;
for (int index = 0; index < arr.length; index++)

{
    sum += arr[index];
}


for-each loop:

int sum =0;
for (int index:arr)

{
    sum += index;
}

I also referenced the following link:

http://forums.devarticles.com/java-development-38/java-changing-while-loop-to-for-loop-169122.html

1 comment:

  1. Good job, and thanks for sharing the resource for others to see. 100 XPs awarded for this completion.

    ReplyDelete