// This program contains several examples of for loops to generate text // figures. public class ForLoopExamples { public static void main(String[] args) { /* for loop--control structure for (init; test; update) { body } */ /* output of this loop is: 1 squared = 1 2 squared = 4 3 squared = 9 4 squared = 16 */ for (int i = 1; i <= 4; i++) { System.out.println(i + " squared = " + (i * i)); } System.out.println(); /* output of this loop is: T-minus 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, blastoff! */ System.out.print("T-minus "); for (int i = 10; i >= 1; i--) { System.out.print(i + ", "); } System.out.println("blastoff!"); System.out.println(); /* output of this loop is: ********** ********** ********** ********** ********** */ for (int i = 1; i <= 5; i++) { // System.out.println("**********"); for (int j = 1; j <= 10; j++) { System.out.print("*"); } System.out.println(); } System.out.println(); /* output of this loop is: * ** *** **** ***** */ for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } System.out.println(); /* output of this loop is: 1 22 333 4444 55555 */ for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(i); } System.out.println(); } System.out.println(); /* output of this loop is: 1 12 123 1234 12345 */ for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); } System.out.println(); System.out.println("That's all folks..."); } }