Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

White a recursive method in java to produce pattern of 2*n lines of asterisks. T

ID: 3940157 • Letter: W

Question

White a recursive method in java to produce pattern of 2*n lines of asterisks. The first line contains 1 asterisk, the next two, the next 3, and so on up to the nth line which contains n asterisks. Line n+1 also contains asterisks, the next has n-1, the next has n-2, and so on until line 2n which contains 1 asterisk.

Explanation / Answer

// bootstrap method to start the recursion public static void myMethod(int length) { myMethod(length, length); } public static void myMethod(int length, int i) { if (i > 0) { int rowLength = length - i + 1; printRow(rowLength, '*'); myMethod(length, i - 1); printRow(rowLength, '*'); } } public static void printRow(int length, char symbol) { for (int i = 0; i