// Here is a program that illustrates nested loops used in output. // Note the "triangular" nature of these loops -- this happens when // one of the bounds (either the lower or upper bound) is an outer loop // variable instead of a constant. public class Loop3 { public static void main(String [] args) { int i, j, topNumber; // The topNumber determines how big each triangle will be. for (topNumber = 20; topNumber <= 40; topNumber += 5) { // The line number i starts at topNumber, and decrements by 5 for (i = topNumber; i >= 10; i -= 5) { // Within a line, we start at j=i, and increment by 5 for (j = i; j <= topNumber; j += 5) { System.out.printf("%d ", j); } System.out.printf("\n"); } System.out.printf("\n"); } } } /* Here is the output: 20 15 20 10 15 20 25 20 25 15 20 25 10 15 20 25 30 25 30 20 25 30 15 20 25 30 10 15 20 25 30 35 30 35 25 30 35 20 25 30 35 15 20 25 30 35 10 15 20 25 30 35 40 35 40 30 35 40 25 30 35 40 20 25 30 35 40 15 20 25 30 35 40 10 15 20 25 30 35 40 */