diff --git a/source/ch5_loopsanditeration.ptx b/source/ch5_loopsanditeration.ptx index 28cbde4..7c6819b 100644 --- a/source/ch5_loopsanditeration.ptx +++ b/source/ch5_loopsanditeration.ptx @@ -183,6 +183,59 @@ public class StringIterationExample { + + +

+ Rearrange the blocks to create a Java method that accepts an upper bound integer limit and calculates the sum of all even numbers from 2 up to and including limit. +

+
+ + + public int sumEvens(int limit) { + + + + + int total = 0; + + + int total; + + + + + + for (int i = 2; i <= limit; i += 2) { + + + for (int i = 2; i < limit; i =+ 2) { + + + + + + total += i; + } + + + total = i; + } + + + + + + return total; + } + + + return i; + } + + + +
+