public class Redundant { public static void main(String[] args) { redundant1(); redundant2(); redundant3(); } public static void redundant1() { /* 1. run initialization statement int i = 1; 2. repeats the following: - checks the test statement to see whether it is true i <= 10 - if the test is true, execute the statements between { } System.out.println("*****"); - executes the update statement i++; - if test is false, stop. */ // Let's print some redundant lines. /* run this line with i = 1 run this line with i = 2 run this line with i = 3 ... run this line with i = 10 stop */ for (int i = 1; i <= 10; i++) { System.out.println("*****"); System.out.println("+++++"); } System.out.println("What is x++++++++++++++++++++++++++++++ ?"); // System.out.println("1 2 3 4 5"); for (int i = 1; i <= 5; i++) { System.out.print(i + " "); } System.out.println(); // end the line from the previous loop // for (int i = 3; i <= 11; i += 2) { // System.out.print(i + " "); //} for (int i = 1; i <= 5; i++) { System.out.print((2 * i + 1) + " "); } System.out.println(); } public static void redundant2() { // This is a bit trickier... for (int line = 1; line <= 5; line++) { // System.out.println("1 2 3 4 5"); for (int j = 1; j <= 5; j++) { System.out.print(j + " "); } } System.out.println(); // end the line from the previous loop /* System.out.println("*"); System.out.println("**"); System.out.println("***"); System.out.println("****"); System.out.println("*****"); print 1 star print 2 stars print 3 stars print 4 stars print 5 stars for each of the numbers 1-5, print that many stars */ for (int i = 1; i <= 5; i++) { // print i stars for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } System.out.println("1"); System.out.println("12"); System.out.println("123"); System.out.println("1234"); System.out.println("12345"); /* System.out.println(" *"); System.out.println(" **"); System.out.println(" ***"); System.out.println(" ****"); System.out.println("*****"); line # spaces # stars 1 4 1 2 3 2 3 2 3 4 1 4 5 0 5 */ for (int line = 1; line <= 5; line++) { int numberOfSpaces = 5 - line; for (int j = 1; j <= numberOfSpaces; j++) { System.out.print(" "); } for (int j = 1; j <= line; j++) { System.out.print("*"); } System.out.println(); } } public static void redundant3() { // Difficult to figure out this figure... System.out.println("#*********#"); /* # stars = (-2 * line) + 9 line | # spaces # stars # spaces | 1 1 7 2 2 5 3 3 3 4 4 1 System.out.println("| ******* |"); System.out.println("| ***** |"); System.out.println("| *** |"); System.out.println("| * |"); */ for (int line = 1; line <= 4; line++) { System.out.print("|"); for (int j = 1; j <= line; j++) { System.out.print(" "); } for (int j = 1; j <= (-2 * line) + 9; j++) { System.out.print("*"); } for (int j = 1; j <= line; j++) { System.out.print(" "); } System.out.print("|"); System.out.println(); } System.out.println("| * |"); System.out.println("| *** |"); System.out.println("| ***** |"); System.out.println("| ******* |"); System.out.println("#*********#"); } }