// Several for-loop practice problems public class OtherPractice { public static void main(String[] args) { printSquares(); System.out.println(); blastoff(); System.out.println(); printStars(); System.out.println(); pyramid(); System.out.println(); } // display the squares of numbers 1-4 public static void printSquares() { /* for (init; test; update) { body } */ for (int i = 1; i <= 4; i = i + 1) { System.out.println(i + " squared = " + (i * i)); } System.out.println("That's all folks..."); } // display the following text: // 10! 9! 8! 7! 6! 5! 4! 3! 2! 1! // blastoff! public static void blastoff() { for (int i = 10; i >= 1; i--) { System.out.print(i + "! "); } System.out.println(); System.out.println("blastoff!"); } /* display the following square of stars: ********** ********** ********** ********** ********** */ public static void printStars() { for (int i = 1; i <= 5; i++) { /* We started off with this println: System.out.println("**********"); but then replicated this line with the following for-loop & println(). */ for (int j = 1; j <= 10; j++) { System.out.print("*"); } System.out.println(); } } /* display a pyramid of stars * ** *** **** ***** */ public static void pyramid() { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } } }