/* Loops3.java CIS 160 David Klick 2004-09-17 Demonstrates repetition and accumulators */ public class Loops3 { public static void main(String[] args) { int i; int accum; System.out.println("This program adds up the numbers from 1 to 10" + " using different types of loops."); System.out.print("\nA do loop: "); i = 1; accum = 0; do { accum = accum + i; i++; } while (i <= 10); System.out.print(accum); // this is called a pre-test loop because the test // is at the beginning of the loop System.out.print("\nA while loop: "); i = 1; accum = 0; while (i <= 10) { accum = accum + i; i++; } System.out.print(accum); // the for loop is also a pre-test loop System.out.print("\nA for loop: "); accum = 0; for (i=1; i<=10; i++) { accum = accum + i; } System.out.print(accum); } }