There are some similar questions on the site that have helped a bit, but I canโt completely solve this problem, so I hope this does not happen again.
This is homework in which you have the character set [A, B, C] and must use recursion to get all permutations (with repetition). The code I have does this:
char[] c = {'A', 'B' , 'C'}; public void printAll(char[] c, int n, int k) { if (k == n) { System.out.print(c); return; } else { for (int j = 0; j<n; j++) { for (int m = 0; m<n; m++) { System.out.print(c[k]); System.out.print(c[j]); System.out.print(c[m] + "\r\n"); } } } printAll(c, n, k+1); }
However, the parameter n must determine the length of the output, so while this function displays all permutations of length 3, it cannot perform their lengths 2. I tried everything I could think of and looked at Google for the search results, and Iโm aggravated with myself that I couldnโt solve what seems like a pretty simple problem.
java arrays recursion permutation
user1788424
source share