// Helene Martin, CSE 142 // Demonstrates nested loops where the inner loop uses the outer loop // counter as part of its bounds. public class LoopPatterns { public static void main(String[] args) { triangle(); dotsNums(); } /* display the following triangle: * ** *** **** ***** */ public static void triangle() { for (int line = 1; line <= 5; line++) { for (int star = 1; star <= line; star++) { System.out.print("*"); } System.out.println(); } } /* Mapping complex patterns to loop counters ....1 ...2 ..3 .4 5 line dots -1 * line -1 * line + 5 1 4 -1 4 2 3 -2 3 3 2 -3 2 4 1 -4 5 0 */ public static void dotsNums() { for (int line = 1; line <= 5; line++) { for (int dots = 1; dots <= -1 * line + 5; dots++) { System.out.print("."); } System.out.println(line); } } }