// Examples using for loops public class ForLoops { public static void main(String[] args) { printSquares(); System.out.println(); blastoff(); System.out.println(); square(); System.out.println(); pyramid(); System.out.println(); numberPyramid(); System.out.println(); lineNumberPyramid(); System.out.println(); } /* display the following output: 1 squared = 1 2 squared = 4 3 squared = 9 4 squared = 16 5 squared = 25 6 squared = 36 Done! */ public static void printSquares() { for (int i = 1; i <= 6; i++) { System.out.println(i + " squared = " + (i * i)); } System.out.println("Done!"); } // display the following text: // T-minus 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, blastoff! public static void blastoff() { System.out.print("T-minus "); for (int i = 10; i >= 1; i--) { System.out.print(i + ", "); } System.out.println("blastoff!"); } /* display the following square of stars: ********** ********** ********** ********** ********** */ public static void square() { for (int line = 1; line <= 5; line++) { for (int star = 1; star <= 10; star++) { System.out.print("*"); } System.out.println(); } } /* display a pyramid of stars * ** *** **** ***** */ public static void pyramid() { for (int line = 1; line <= 5; line++) { for (int star = 1; star <= line; star++) { System.out.print("*"); } System.out.println(); } } /* display a pyramid of numbers 1 12 123 1234 12345 */ public static void numberPyramid() { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(j); } System.out.println(); } } /* display a pyramid of line numbers 1 22 333 4444 55555 */ public static void lineNumberPyramid() { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(i); } System.out.println(); } } }