White a recursive method in java to produce pattern of 2n li

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.

Solution

// 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 < length; i++) System.out.print(symbol); System.out.println(); }
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site