public class RecursionExercises { /** * @return a string consisting of n copies of the character c */ static String genChars(char c, int n) { if (n == 0) return ""; return c + genChars(c, n-1); } /** * @return a string consisting of b blanks followed by * k copies of the non-blank character c */ static String genLine(char c, int k, int b) { return genChars(' ', b) + genChars(c, k); } /** * @return A string represting a "right-justified" triangle * each side of which has n non-blank character c, and each * line of output is len characters long */ static String genTriangle(char c, int n, int len) { if (n == 0) return ""; return genTriangle(c, n-1, len) + genLine(c, n, len-n) + "\n"; } public static void main(String[] args) { int n = Integer.parseInt(args[0]); System.out.print(genTriangle('*', n, n)); } }