| 1 | /** Sum from 2,3 & 4, then 3,4, 5 and then 4,5,6 and print total; | 1 |
| 2 | **/ | 2 |
| 3 | public class SumNumbers | 3 |
| 4 | { | 4 |
| 5 | public static void main (String [] args) | 5 |
| 6 | { | 6 |
| 7 | int sum; // holds the total of all | 7 |
| 8 | int sumEachSet; // holds the total of the most recent series | 8 |
| 9 | sum = 0; | 9 |
| 10 | for (int counter = 1; counter <= 3 ; counter++) // run 3 series | 10 |
| 11 | { | 11 |
| 12 | sumEachSet = 0; | 12 |
| 13 | for (int numberToAdd = counter+1; numberToAdd < counter+4;numberToAdd++) | 13 |
| 14 | { System.out.println("The number is " + numberToAdd); | 14 |
| 15 | sumEachSet = numberToAdd + sumEachSet; | 15 |
| 16 | } | 16 |
| 17 | System.out.println("The sum of set # " + counter + " is " + sumEachSet ); | 17 |
| 18 | sum = sum + sumEachSet; | 18 |
| 19 | } | 19 |
| 20 | System.out.println("The sum of all numbers is " + sum ); | 20 |
| 21 | } | 21 |
| 22 | } | 22 |